expander.cpp
来自「LINUX 下, 以 QT/KDE 写的档案管理员」· C++ 代码 · 共 1,225 行 · 第 1/3 页
CPP
1,225 行
_needPanel = true;}TagString exp_Filter::expFunc( const ListPanel* panel, const QStringList&, const bool&, Expander& exp ) const { NEED_PANEL return panel->view->filterMask().nameFilter();}exp_Current::exp_Current() { _expression = "Current"; _description = i18n("Current File (!= Selected File)..."); _needPanel = true; addParameter( exp_parameter( i18n("Omit the current path (optional)"), "__no", false ) ); addParameter( exp_parameter( i18n("Automatically escape spaces"), "__yes", false ) );}TagString exp_Current::expFunc( const ListPanel* panel, const QStringList& parameter, const bool& useUrl, Expander& exp ) const { NEED_PANEL QString item = panel->view->getCurrentItem(); QString result; if ( parameter[0].lower() == "yes" ) // ommit the current path result = item; else { KURL url = panel->func->files()->vfs_getFile( item ); if ( useUrl ) result = url.url(); else result = url.path(); } if ( parameter[1].lower() == "no" ) // don't escape spaces return result; else return bashquote(result);}exp_List::exp_List() { _expression = "List"; _description = i18n("Item List of..."); _needPanel = true; addParameter( exp_parameter( i18n("Which items:"), "__choose:All;Files;Dirs;Selected", false ) ); addParameter( exp_parameter( i18n("Separator between the items (optional):"), " ", false ) ); addParameter( exp_parameter( i18n("Omit the current path (optional)"), "__no", false ) ); addParameter( exp_parameter( i18n("Mask (optional, all but 'Selected'):"), "__select", false ) ); addParameter( exp_parameter( i18n("Automatically escape spaces"), "__yes", false ) );}TagString exp_List::expFunc( const ListPanel* panel, const QStringList& parameter, const bool& useUrl, Expander& exp ) const { NEED_PANEL // get selected items from view QStringList items; QString mask; if ( parameter.count() <= 3 || parameter[3].isEmpty() ) mask = "*"; else mask = parameter[3]; return separateAndQuote( fileList(panel, parameter.empty() ? QString::null : parameter[0].lower(), mask, parameter.count() > 2 ? parameter[2].lower()=="yes" : false, useUrl, exp, "List"), parameter.count() > 1 ? parameter[1] : " ", parameter.count() > 4 ? parameter[4].lower()=="yes" : true);}exp_ListFile::exp_ListFile() { _expression = "ListFile"; _description = i18n("Filename of an Item List..."); _needPanel = true; addParameter( exp_parameter( i18n("Which items:"), "__choose:All;Files;Dirs;Selected", false ) ); addParameter( exp_parameter( i18n("Separator between the items (optional)"), "\n", false ) ); addParameter( exp_parameter( i18n("Omit the current path (optional)"), "__no", false ) ); addParameter( exp_parameter( i18n("Mask (optional, all but 'Selected'):"), "__select", false ) ); addParameter( exp_parameter( i18n("Automatically escape spaces"), "__no", false ) );}TagString exp_ListFile::expFunc( const ListPanel* panel, const QStringList& parameter, const bool& useUrl, Expander& exp ) const { NEED_PANEL // get selected items from view QStringList items; QString mask; if ( parameter.count() <= 3 || parameter[3].isEmpty() ) mask = "*"; else mask = parameter[3]; KTempFile tmpFile( locateLocal("tmp", "krusader"), ".itemlist" ); if ( tmpFile.status() != 0 ) { setError(exp, Error(Error::S_FATAL,Error::C_WORLD, i18n("Expander: tempfile couldn't be opened (%1)" ).arg(strerror( tmpFile.status() )) )); return QString::null; } QTextStream stream( tmpFile.file() ); stream << separateAndQuote( fileList(panel, parameter.empty() ? QString::null : parameter[0].lower(), mask, parameter.count()>2 ? parameter[2].lower()=="yes" : false, useUrl, exp, "ListFile"), parameter.count() > 1 ? parameter[1] : "\n", parameter.count() > 4 ? parameter[4].lower()=="yes" : true) << "\n"; tmpFile.close(); return tmpFile.name();}exp_Select::exp_Select() { _expression = "Select"; _description = i18n("Manipulate the Selection..."); _needPanel = true; addParameter( exp_parameter( i18n("Selection mask:"), "__select", true ) ); addParameter( exp_parameter( i18n("Manipulate in which way:"), "__choose:Set;Add;Remove", false ) );}TagString exp_Select::expFunc( const ListPanel* panel, const QStringList& parameter, const bool& , Expander& exp) const { NEED_PANEL KRQuery mask; if ( parameter.count() <= 0 || parameter[0].isEmpty() ) mask = KRQuery( "*" ); else mask = KRQuery( parameter[0] ); if ( parameter[1].lower() == "add") panel->view->select( mask ); else if ( parameter[1].lower() == "remove") panel->view->unselect( mask ); else { // parameter[1].lower() == "set" or isEmpty() or whatever panel->view->unselect( KRQuery( "*" ) ); panel->view->select( mask ); } return QString::null; // this doesn't return anything, that's normal!}exp_Goto::exp_Goto() { _expression = "Goto"; _description = i18n("Jump to a Location..."); _needPanel = true; addParameter( exp_parameter( i18n("Choose a path:"), "__goto", true ) ); addParameter( exp_parameter( i18n("Open location in a new tab"), "__no", false ) );}TagString exp_Goto::expFunc( const ListPanel* panel, const QStringList& parameter, const bool&, Expander& exp ) const { NEED_PANEL bool newTab = false; if ( parameter[1].lower() == "yes" ) newTab = true; if ( newTab ) { if ( panel == LEFT_PANEL) krApp->mainView->leftMng->slotNewTab( parameter[0] ); else krApp->mainView->rightMng->slotNewTab( parameter[0] ); } else { panel->func->openUrl( parameter[0], "" ); const_cast<ListPanel*>(panel)->slotFocusOnMe(); } return QString::null; // this doesn't return anything, that's normal!}/*exp_Search::exp_Search() { _expression = "Search"; _description = i18n("Search for files"); _needPanel = true; addParameter( new exp_parameter( i18n("please choose the setting"), "__searchprofile", true ) ); addParameter( new exp_parameter( i18n("open the search in a new tab"), "__yes", false ) ); //TODO: add this also to panel-dependent as soon as vfs support the display of search-results}*/exp_Ask::exp_Ask() { _expression = "Ask"; _description = i18n("Ask Parameter from User..."); _needPanel = false; addParameter( exp_parameter( i18n("Question:"), "Where do you want do go today?", true ) ); addParameter( exp_parameter( i18n("Preset (optional):"), "", false ) ); addParameter( exp_parameter( i18n("Caption (optional):"), "", false ) );}TagString exp_Ask::expFunc( const ListPanel*, const QStringList& parameter, const bool&, Expander& exp ) const { QString caption, preset, result; if ( parameter.count() <= 2 || parameter[2].isEmpty() ) caption = i18n("User Action"); else caption = parameter[2]; if ( parameter.count() <= 1 || parameter[1].isEmpty() ) preset = QString::null; else preset = parameter[1]; bool ok; result = KInputDialog::getText( caption, parameter[0], preset, &ok ); if (ok) return result; else { setError(exp, Error(Error::S_ERROR,Error::C_USER,"User cancelled") ); return QString::null; }}exp_Clipboard::exp_Clipboard() { _expression = "Clipboard"; _description = i18n("Copy to Clipboard..."); _needPanel = false; addParameter( exp_parameter( i18n("What to copy:"), "__placeholder", true ) ); addParameter( exp_parameter( i18n("Append to current clipboard content with this separator (optional):"), "", false ) );}TagString exp_Clipboard::expFunc( const ListPanel*, const TagStringList& parameter, const bool&, Expander& exp ) const {// kdDebug() << "Expander::exp_Clipboard, parameter[0]: '" << parameter[0] << "', Clipboard: " << KApplication::clipboard()->text() << endl; QStringList lst=splitEach(parameter[0]); if(!parameter[1].isSimple()) { setError(exp,Error(Error::S_FATAL,Error::C_SYNTAX,i18n("Expander: %Each% may not be in the second argument of %Clipboard%"))); return QString::null; } if ( parameter.count() <= 1 || parameter[1].string().isEmpty() || KApplication::clipboard()->text().isEmpty() ) KApplication::clipboard()->setText( lst.join("\n") ); else KApplication::clipboard()->setText( KApplication::clipboard()->text() + parameter[1].string() + lst.join("\n") ); return QString::null; // this doesn't return anything, that's normal!}exp_Copy::exp_Copy() { _expression = "Copy"; _description = i18n("Copy a File/Folder..."); _needPanel = false; addParameter( exp_parameter( i18n("What to copy:"), "__placeholder", true ) ); addParameter( exp_parameter( i18n("Where to copy:"), "__placeholder", true ) );}TagString exp_Copy::expFunc( const ListPanel*, const TagStringList& parameter, const bool&, Expander& exp ) const { // basically the parameter can already be used as URL, but since KURL has problems with ftp-proxy-urls (like ftp://username@proxyusername@url...) this is neccesary: QStringList lst=splitEach( parameter[0] ); if(!parameter[1].isSimple()) { setError(exp,Error(Error::S_FATAL,Error::C_SYNTAX,i18n("Expander: %Each% may not be in the second argument of %Copy%"))); return QString::null; } KURL::List src; for(QStringList::const_iterator it=lst.begin(),end=lst.end();it!=end;++it) src.push_back(vfs::fromPathOrURL( *it )); // or transform(...) ? KURL dest = vfs::fromPathOrURL( parameter[1].string() ); if ( !dest.isValid() || find_if(src.constBegin(),src.constEnd(),not1(mem_fun_ref(&KURL::isValid) ))!=src.end()) { setError(exp, Error(Error::S_FATAL,Error::C_ARGUMENT,i18n("Expander: invalid URL's in %_Copy(\"src\", \"dest\")%") )); return QString::null; } PreservingCopyJob::createCopyJob( PM_DEFAULT, src, dest, KIO::CopyJob::Copy, false, true ); return QString::null; // this doesn't return everything, that's normal!}exp_Move::exp_Move() { _expression = "Move"; _description = i18n("Move/Rename a File/Folder..."); _needPanel = false; addParameter( exp_parameter( i18n("What to move/rename:"), "__placeholder", true ) ); addParameter( exp_parameter( i18n("New target/name:"), "__placeholder", true ) );} TagString exp_Move::expFunc( const ListPanel*, const TagStringList& parameter, const bool& , Expander& exp ) const { // basically the parameter can already be used as URL, but since KURL has problems with ftp-proxy-urls (like ftp://username@proxyusername@url...) this is neccesary: QStringList lst=splitEach( parameter[0] ); if(!parameter[1].isSimple()) { setError(exp,Error(Error::S_FATAL,Error::C_SYNTAX,i18n("%Each% may not be in the second argument of %Move%"))); return QString::null; } KURL::List src; for(QStringList::const_iterator it=lst.begin(),end=lst.end();it!=end;++it) src.push_back(vfs::fromPathOrURL( *it )); // or transform(...) ? KURL dest = vfs::fromPathOrURL( parameter[1].string() ); if ( !dest.isValid() || find_if(src.constBegin(),src.constEnd(),not1(mem_fun_ref(&KURL::isValid) ))!=src.end()) { setError(exp, Error(Error::S_FATAL,Error::C_ARGUMENT,i18n("Expander: invalid URL's in %_Move(\"src\", \"dest\")%") )); return QString::null; } PreservingCopyJob::createCopyJob( PM_DEFAULT, src, dest, KIO::CopyJob::Move, false, true ); return QString::null; // this doesn't return anything, that's normal!}exp_Sync::exp_Sync() { _expression = "Sync"; _description = i18n("Load a Synchronizer Profile..."); _needPanel = false; addParameter( exp_parameter( i18n("Choose a profile:"), "__syncprofile", true ) );}TagString exp_Sync::expFunc( const ListPanel*, const QStringList& parameter, const bool&, Expander& exp ) const { if ( parameter[0].isEmpty() ) { setError(exp, Error(Error::S_FATAL,Error::C_ARGUMENT,i18n("Expander: no profile specified for %_Sync(profile)%") )); return QString::null; } new SynchronizerGUI( 0, parameter[0] ); return QString::null; // this doesn't return everything, that's normal!}exp_NewSearch::exp_NewSearch() { _expression = "NewSearch"; _description = i18n("Load a Searchmodule Profile..."); _needPanel = false; addParameter( exp_parameter( i18n("Choose a profile:"), "__searchprofile", true ) );}TagString exp_NewSearch::expFunc( const ListPanel*, const QStringList& parameter, const bool&, Expander& exp ) const { if ( parameter[0].isEmpty() ) { setError(exp, Error(Error::S_FATAL,Error::C_ARGUMENT,i18n("Expander: no profile specified for %_NewSearch(profile)%") )); return QString::null; } new KrSearchDialog( parameter[0], krApp ); return QString::null; // this doesn't return everything, that's normal!}exp_Profile::exp_Profile() { _expression = "Profile"; _description = i18n("Load a Panel Profile..."); _needPanel = false; addParameter( exp_parameter( i18n("Choose a profile:"), "__panelprofile", true ) );}TagString exp_Profile::expFunc( const ListPanel*, const QStringList& parameter, const bool&, Expander& exp ) const { if ( parameter[0].isEmpty() ) { setError(exp, Error(Error::S_FATAL,Error::C_ARGUMENT,i18n("Expander: no profile specified for %_Profile(profile)%; abort...") )); return QString::null; } MAIN_VIEW->profiles( parameter[0] ); return QString::null; // this doesn't return everything, that's normal!}exp_Each::exp_Each() { _expression = "Each"; _description = i18n("Separate Program Call for Each..."); _needPanel = true; addParameter( exp_parameter( i18n("Which items:"), "__choose:All;Files;Dirs;Selected", false ) ); addParameter( exp_parameter( i18n("Omit the current path (optional)"), "__no", false ) ); addParameter( exp_parameter( i18n("Mask (optional, all but 'Selected'):"), "__select", false ) ); addParameter( exp_parameter( i18n("Automatically escape spaces"), "__yes", false ) );}TagString exp_Each::expFunc( const ListPanel* panel, const QStringList& parameter, const bool& useUrl, Expander& exp ) const { NEED_PANEL QString mask; if ( parameter.count() <= 2 || parameter[2].isEmpty() ) mask = "*"; else mask = parameter[2]; TagString ret; QStringList l = fileList(panel, parameter.empty() ? QString::null : parameter[0].lower(), mask, parameter.count() > 1 && parameter[1].lower()=="yes", useUrl, exp, "Each"); if(!(parameter.count()<=3 || parameter[3].lower()!="yes")) transform(l.begin(),l.end(),l.begin(),bashquote); ret.insertTag(0,l); return ret;}exp_ColSort::exp_ColSort() { _expression = "ColSort"; _description = i18n("Set Sorting for This Panel..."); _needPanel = true; addParameter( exp_parameter( i18n("Choose a column:"), "__choose:Name;Ext;Type;Size;Modified;Perms;rwx;Owner;Group", true ) ); addParameter( exp_parameter( i18n("Choose a sort sequence:"), "__choose:Toggle;Asc;Desc", false ) );}TagString exp_ColSort::expFunc( const ListPanel* panel, const QStringList& parameter, const bool&, Expander& exp ) const { NEED_PANEL if ( parameter[0].isEmpty() ) { setError(exp, Error(Error::S_FATAL,Error::C_ARGUMENT,i18n("Expander: no column specified for %_ColSort(column)%") )); return QString::null; } int mode = (int) panel->view->sortMode();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?