File indexing completed on 2024-04-28 04:58:27
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 //#include "konq_treepart.h" 0008 #include "konq_sidebartreemodule.h" 0009 #include <kdirnotify.h> 0010 #include <kio/paste.h> 0011 #include <kprotocolinfo.h> 0012 #include <k3urldrag.h> 0013 #include <kconfiggroup.h> 0014 #include <kfileitem.h> 0015 #include <kmimetype.h> 0016 #include <QApplication> 0017 #include <QClipboard> 0018 #include <QCursor> 0019 #include <QMimeData> 0020 #include <kdesktopfile.h> 0021 0022 void KonqSidebarTreeTopLevelItem::init() 0023 { 0024 QString desktopFile = m_path; 0025 if (isTopLevelGroup()) { 0026 desktopFile += "/.directory"; 0027 } 0028 KDesktopFile cfg(desktopFile); 0029 m_comment = cfg.desktopGroup().readEntry("Comment"); 0030 } 0031 0032 void KonqSidebarTreeTopLevelItem::setOpen(bool open) 0033 { 0034 if (open && module()) { 0035 module()->openTopLevelItem(this); 0036 } 0037 KonqSidebarTreeItem::setOpen(open); 0038 } 0039 0040 void KonqSidebarTreeTopLevelItem::itemSelected() 0041 { 0042 qCDebug(SIDEBAR_LOG) << "KonqSidebarTreeTopLevelItem::itemSelected"; 0043 const QMimeData *data = QApplication::clipboard()->mimeData(); 0044 const bool paste = m_bTopLevelGroup && data->hasUrls(); 0045 tree()->enableActions(true, true, paste); 0046 } 0047 0048 bool KonqSidebarTreeTopLevelItem::acceptsDrops(const Q3StrList &formats) 0049 { 0050 return formats.contains("text/uri-list") && 0051 (m_bTopLevelGroup || !externalURL().isEmpty()); 0052 } 0053 0054 void KonqSidebarTreeTopLevelItem::drop(QDropEvent *ev) 0055 { 0056 if (m_bTopLevelGroup) { 0057 // When dropping something to "Network" or its subdirs, we want to create 0058 // a desktop link, not to move/copy/link - except for .desktop files :-} 0059 QList<QUrl> lst; 0060 if (K3URLDrag::decode(ev, lst) && !lst.isEmpty()) { // Are they urls ? 0061 QList<QUrl>::Iterator it = lst.begin(); 0062 for (; it != lst.end(); it++) { 0063 tree()->addUrl(this, *it); 0064 } 0065 } else { 0066 kError() << "No URL !? " << endl; 0067 } 0068 } else { // Top level item, not group 0069 if (!externalURL().isEmpty()) { 0070 KonqOperations::doDrop(KFileItem(), externalURL(), ev, tree()); 0071 } 0072 } 0073 } 0074 0075 bool KonqSidebarTreeTopLevelItem::populateMimeData(QMimeData *mimeData, bool move) 0076 { 0077 QList<QUrl> lst; 0078 lst.append(QUrl::fromLocalFile(path())); 0079 0080 mimeData->setUrls(lst); 0081 KIO::setClipboardDataCut(mimeData, move); 0082 0083 #if 0 0084 const QPixmap *pix = pixmap(0); 0085 if (pix) { 0086 QPoint hotspot(pix->width() / 2, pix->height() / 2); 0087 drag->setPixmap(*pix, hotspot); 0088 } 0089 #endif 0090 0091 return true; 0092 } 0093 0094 void KonqSidebarTreeTopLevelItem::middleButtonClicked() 0095 { 0096 if (!m_bTopLevelGroup) { 0097 emit tree()->createNewWindow(m_externalURL); 0098 } 0099 // Do nothing for toplevel groups 0100 } 0101 0102 void KonqSidebarTreeTopLevelItem::rightButtonPressed() 0103 { 0104 QUrl url; 0105 url.setPath(m_path); 0106 // We don't show "edit file type" (useless here) and "properties" (shows the wrong name, 0107 // i.e. the filename instead of the Name field). There's the Rename item for that. 0108 // Only missing thing is changing the URL of a link. Hmm... 0109 0110 if (!module() || !module()->handleTopLevelContextMenu(this, QCursor::pos())) { 0111 tree()->showToplevelContextMenu(); 0112 } 0113 } 0114 0115 void KonqSidebarTreeTopLevelItem::trash() 0116 { 0117 delOperation(KonqOperations::TRASH); 0118 } 0119 0120 void KonqSidebarTreeTopLevelItem::del() 0121 { 0122 delOperation(KonqOperations::DEL); 0123 } 0124 0125 void KonqSidebarTreeTopLevelItem::delOperation(KonqOperations::Operation method) 0126 { 0127 QUrl url(m_path); 0128 QList<QUrl> lst; 0129 lst.append(url); 0130 0131 KonqOperations::del(tree(), method, lst); 0132 } 0133 0134 void KonqSidebarTreeTopLevelItem::paste() 0135 { 0136 // move or not move ? 0137 bool move = false; 0138 const QMimeData *data = QApplication::clipboard()->mimeData(); 0139 if (data->hasFormat("application/x-kde-cutselection")) { 0140 move = KonqMimeData::decodeIsCutSelection(data); 0141 qCDebug(SIDEBAR_LOG) << "move (from clipboard data) = " << move; 0142 } 0143 0144 QUrl destURL; 0145 if (m_bTopLevelGroup) { 0146 destURL.setPath(m_path); 0147 } else { 0148 destURL = m_externalURL; 0149 } 0150 0151 KIO::pasteClipboard(destURL, 0L, move); 0152 } 0153 0154 void KonqSidebarTreeTopLevelItem::rename() 0155 { 0156 tree()->rename(this, 0); 0157 } 0158 0159 void KonqSidebarTreeTopLevelItem::rename(const QString &name) 0160 { 0161 QUrl url(m_path); 0162 0163 // Adjust the Name field of the .directory or desktop file 0164 QString desktopFile = m_path; 0165 if (isTopLevelGroup()) { 0166 desktopFile += "/.directory"; 0167 } 0168 KDesktopFile cfg(desktopFile); 0169 cfg.desktopGroup().writeEntry("Name", name); 0170 cfg.sync(); 0171 0172 // Notify about the change 0173 QList<QUrl> lst; 0174 lst.append(url); 0175 OrgKdeKDirNotifyInterface::emitFilesChanged(lst.toStringList()); 0176 } 0177 0178 QString KonqSidebarTreeTopLevelItem::toolTipText() const 0179 { 0180 return m_comment; 0181 } 0182