void KrViewOperator::quickSearch(const QString & str, int direction) { KrViewItem * item = _view->getCurrentKrViewItem(); if (!item) { _quickSearch->setMatch(false); return; } KConfigGroup grpSvr(_view->_config, "Look&Feel"); bool caseSensitive = grpSvr.readEntry("Case Sensitive Quicksearch", _CaseSensitiveQuicksearch); QRegExp rx(str, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard); if (!direction) { if (rx.indexIn(item->name()) == 0) { _quickSearch->setMatch(true); return ; } direction = 1; } KrViewItem * startItem = item; while (true) { item = (direction > 0) ? _view->getNext(item) : _view->getPrev(item); if (!item) item = (direction > 0) ? _view->getFirst() : _view->getLast(); if (item == startItem) { _quickSearch->setMatch(false); return ; } if (rx.indexIn(item->name()) == 0) { _view->setCurrentKrViewItem(item); _view->makeItemVisible(item); _quickSearch->setMatch(true); return ; } } }
/** * this function ADDs a list of selected item names into 'names'. * it assumes the list is ready and doesn't initialize it, or clears it */ void KrView::getItemsByMask(QString mask, QStringList* names, bool dirs, bool files) { for (KrViewItem * it = getFirst(); it != 0; it = getNext(it)) { if ((it->name() == "..") || !QDir::match(mask, it->name())) continue; // if we got here, than the item fits the mask if (it->getVfile()->vfile_isDir() && !dirs) continue; // do we need to skip folders? if (!it->getVfile()->vfile_isDir() && !files) continue; // do we need to skip files names->append(it->name()); } }
/** * this function ADDs a list of selected item names into 'names'. * it assumes the list is ready and doesn't initialize it, or clears it */ void KrView::getSelectedItems(QStringList *names, bool ignoreJustFocused) { for (KrViewItem * it = getFirst(); it != 0; it = getNext(it)) if (it->isSelected() && (it->name() != "..")) names->append(it->name()); // if all else fails, take the current item if (!ignoreJustFocused) { QString item = getCurrentItem(); if (names->empty() && !item.isEmpty() && item != "..") { names->append(item); } } }
void KrView::getSelectedKrViewItems(KrViewItemList *items) { for (KrViewItem * it = getFirst(); it != 0; it = getNext(it)) if (it->isSelected() && (it->name() != "..")) items->append(it); // if all else fails, take the current item QString item = getCurrentItem(); if (items->empty() && !item.isEmpty() && item != ".." && getCurrentKrViewItem() != 0) { items->append(getCurrentKrViewItem()); } }
KrPopupMenu::KrPopupMenu(KrPanel *thePanel, QWidget *parent) : QMenu(parent), panel(thePanel), empty(false), multipleSelections(false), actions(0), _item(0) { #ifdef __LIBKONQ__ konqMenu = 0; konqMenuActions = 0; #endif KrViewItemList items; panel->view->getSelectedKrViewItems(&items); for (KrViewItemList::Iterator it = items.begin(); it != items.end(); ++it) { vfile *file = panel->func->files()->vfs_search(((*it)->name())); QUrl url = file->vfile_getUrl(); _items.append(KFileItem(url, file->vfile_getMime(), file->vfile_getMode())); } if (items.empty()) { addCreateNewMenu(); addSeparator(); addEmptyMenuEntries(); return; } else if (items.size() > 1) multipleSelections = true; QList<QString> protocols; for (int i = 0; i < items.size(); ++i) { protocols.append(panel->func->getVFile(items[ i ]) ->vfile_getUrl().scheme()); } bool inTrash = protocols.contains("trash"); bool trashOnly = (protocols.count() == 1) && (protocols[ 0 ] == "trash"); KrViewItem *item = items.first(); vfile *vf = panel->func->getVFile(item); _item = &_items.first(); // ------------ the OPEN option - open preferred service QAction * openAct = addAction(i18n("Open/Run")); openAct->setData(QVariant(OPEN_ID)); if (!multipleSelections) { // meaningful only if one file is selected openAct->setIcon(item->icon()); openAct->setText(vf->vfile_isExecutable() && !vf->vfile_isDir() ? i18n("Run") : i18n("Open")); // open in a new tab (if folder) if (vf->vfile_isDir()) { QAction * openTab = addAction(i18n("Open in New Tab")); openTab->setData(QVariant(OPEN_TAB_ID)); openTab->setIcon(krLoader->loadIcon("tab-new", KIconLoader::Panel)); openTab->setText(i18n("Open in New Tab")); } addSeparator(); } // ------------- Preview - normal vfs only ? if (panel->func->files()->vfs_getType() == vfs::VFS_NORMAL) { // create the preview popup QStringList names; panel->gui->getSelectedNames(&names); preview.setUrls(panel->func->files() ->vfs_getFiles(names)); QAction *pAct = addMenu(&preview); pAct->setData(QVariant(PREVIEW_ID)); pAct->setText(i18n("Preview")); } // -------------- Open with: try to find-out which apps can open the file // this too, is meaningful only if one file is selected or if all the files // have the same mimetype ! QString mime = panel->func->getVFile(item)->vfile_getMime(); // check if all the list have the same mimetype for (int i = 1; i < items.size(); ++i) { if (panel->func->getVFile(items[ i ]) ->vfile_getMime() != mime) { mime.clear(); break; } } if (!mime.isEmpty()) { offers = KMimeTypeTrader::self()->query(mime); for (int i = 0; i < offers.count(); ++i) { QExplicitlySharedDataPointer<KService> service = offers[i]; if (service->isValid() && service->isApplication()) { openWith.addAction(krLoader->loadIcon(service->icon(), KIconLoader::Small), service->name())->setData(QVariant(SERVICE_LIST_ID + i)); } } openWith.addSeparator(); if (vf->vfile_isDir()) openWith.addAction(krLoader->loadIcon("utilities-terminal", KIconLoader::Small), i18n("Terminal"))->setData(QVariant(OPEN_TERM_ID)); openWith.addAction(i18n("Other..."))->setData(QVariant(CHOOSE_ID)); QAction *owAct = addMenu(&openWith); owAct->setData(QVariant(OPEN_WITH_ID)); owAct->setText(i18n("Open With")); addSeparator(); } // --------------- user actions QAction *uAct = new UserActionPopupMenu(panel->func->files()->vfs_getFile(item->name())); addAction(uAct); uAct->setText(i18n("User Actions")); #ifdef __LIBKONQ__ // -------------- konqueror menu // This section adds all Konqueror/Dolphin menu items. // It's now updated to KDE4 and working, I've just commented it out. // Section below this one adds only servicemenus. // Append only servicemenus //TODO: deprecated since KDE4.3: remove these three lines KonqPopupMenuInformation info; info.setItems(_items); info.setParentWidget(this); konqMenuActions = new KonqMenuActions(); //TODO: deprecated since KDE4.3: remove this line, use two commented lines konqMenuActions->setPopupMenuInfo(info); //konqMenuActions->setParentWidget( this ); //konqMenuActions->setItemListProperties( _items ); konqMenuActions->addActionsTo(this); addSeparator(); #endif // ------------- 'create new' submenu addCreateNewMenu(); addSeparator(); // ---------- COPY addAction(i18n("Copy..."))->setData(QVariant(COPY_ID)); if (panel->func->files() ->vfs_isWritable()) { // ------- MOVE addAction(i18n("Move..."))->setData(QVariant(MOVE_ID)); // ------- RENAME - only one file if (!multipleSelections && !inTrash) addAction(i18n("Rename"))->setData(QVariant(RENAME_ID)); // -------- MOVE TO TRASH KConfigGroup saver(krConfig, "General"); bool trash = saver.readEntry("Move To Trash", _MoveToTrash); if (trash && !inTrash) addAction(i18n("Move to Trash"))->setData(QVariant(TRASH_ID)); // -------- DELETE addAction(i18n("Delete"))->setData(QVariant(DELETE_ID)); // -------- SHRED - only one file /* if ( panel->func->files() ->vfs_getType() == vfs::VFS_NORMAL && !vf->vfile_isDir() && !multipleSelections ) addAction( i18n( "Shred" ) )->setData( QVariant( SHRED_ID ) );*/ } // ---------- link handling // create new shortcut or redirect links - only on local directories: if (panel->func->files() ->vfs_getType() == vfs::VFS_NORMAL) { addSeparator(); linkPopup.addAction(i18n("New Symlink..."))->setData(QVariant(NEW_SYMLINK_ID)); linkPopup.addAction(i18n("New Hardlink..."))->setData(QVariant(NEW_LINK_ID)); if (panel->func->getVFile(item)->vfile_isSymLink()) linkPopup.addAction(i18n("Redirect Link..."))->setData(QVariant(REDIRECT_LINK_ID)); QAction *linkAct = addMenu(&linkPopup); linkAct->setData(QVariant(LINK_HANDLING_ID)); linkAct->setText(i18n("Link Handling")); } addSeparator(); // ---------- calculate space if (panel->func->files() ->vfs_getType() == vfs::VFS_NORMAL && (vf->vfile_isDir() || multipleSelections)) addAction(panel->gui->actions()->actCalculate); // ---------- mount/umount/eject if (panel->func->files() ->vfs_getType() == vfs::VFS_NORMAL && vf->vfile_isDir() && !multipleSelections) { if (krMtMan.getStatus(panel->func->files() ->vfs_getFile(item->name()).path()) == KMountMan::MOUNTED) addAction(i18n("Unmount"))->setData(QVariant(UNMOUNT_ID)); else if (krMtMan.getStatus(panel->func->files() ->vfs_getFile(item->name()).path()) == KMountMan::NOT_MOUNTED) addAction(i18n("Mount"))->setData(QVariant(MOUNT_ID)); if (krMtMan.ejectable(panel->func->files() ->vfs_getFile(item->name()).path())) addAction(i18n("Eject"))->setData(QVariant(EJECT_ID)); } // --------- send by mail if (KrServices::supportedTools().contains("MAIL") && !vf->vfile_isDir()) { addAction(i18n("Send by Email"))->setData(QVariant(SEND_BY_EMAIL_ID)); } // --------- empty trash if (trashOnly) { addAction(i18n("Restore"))->setData(QVariant(RESTORE_TRASHED_FILE_ID)); addAction(i18n("Empty Trash"))->setData(QVariant(EMPTY_TRASH_ID)); } #ifdef SYNCHRONIZER_ENABLED // --------- synchronize if (panel->view->numSelected()) { addAction(i18n("Synchronize Selected Files..."))->setData(QVariant(SYNC_SELECTED_ID)); } #endif // --------- copy/paste addSeparator(); addAction(i18n("Copy to Clipboard"))->setData(QVariant(COPY_CLIP_ID)); if (panel->func->files() ->vfs_isWritable()) { addAction(i18n("Cut to Clipboard"))->setData(QVariant(MOVE_CLIP_ID)); addAction(i18n("Paste from Clipboard"))->setData(QVariant(PASTE_CLIP_ID)); } addSeparator(); // --------- properties addAction(panel->gui->actions()->actProperties); }