KRename – powerful batch renamer
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. /***************************************************************************
  2. krenameimpl.cpp - description
  3. -------------------
  4. begin : Die Mai 20 2003
  5. copyright : (C) 2003 by Dominik Seichter
  6. email : domseichter@web.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "krenameimpl.h"
  17. // Own includes
  18. #include "ProgressDialog.h"
  19. #include "confdialog.h"
  20. #include "fileoperation.h"
  21. #include "kmylistview.h"
  22. #include "kmyhistorycombo.h"
  23. #include "pluginloader.h"
  24. #include "replacedialog.h"
  25. #include "undodialog.h"
  26. #include "helpdialog.h"
  27. #include "coorddialog.h"
  28. #include "numberdialog.h"
  29. #include "firststartdlg.h"
  30. #include "wizard.h"
  31. #include "tabs.h"
  32. #include "dsdirselectdialog.h"
  33. #include "krenamedcop.h"
  34. #include "profiledlg.h"
  35. // KDE includes
  36. #include <dcopclient.h>
  37. #include <tdeaboutapplication.h>
  38. #include <tdeapplication.h>
  39. #include <tdeaction.h>
  40. #include <tdecmdlineargs.h>
  41. #include <kdirselectdialog.h>
  42. #include <tdefiledialog.h>
  43. #include <tdefileitem.h>
  44. #include <khelpmenu.h>
  45. #include <kiconloader.h>
  46. #include <tdemessagebox.h>
  47. #include <tdemenubar.h>
  48. #include <tdepopupmenu.h>
  49. #include <kurlrequester.h>
  50. #include <tdetempfile.h>
  51. #include <tdelocale.h>
  52. #include <tdeio/netaccess.h>
  53. // QT includes
  54. #include <tqbuttongroup.h>
  55. #include <tqcursor.h>
  56. #include <tqgrid.h>
  57. #include <tqlabel.h>
  58. #include <tqlayout.h>
  59. #include <tqradiobutton.h>
  60. #include <tqrect.h>
  61. #include <tqregexp.h>
  62. #include <tqtabwidget.h>
  63. #include <tqtimer.h>
  64. #include <tqtooltip.h>
  65. #include <tqvgroupbox.h>
  66. #include <tqvbox.h>
  67. #include <tqvbuttongroup.h>
  68. #include <tqwidget.h>
  69. #include <tqwidgetstack.h>
  70. #define ID_WIZARD 2905
  71. #define ID_TAB 2904
  72. TQCString pageTitle[] = {
  73. I18N_NOOP( "F&iles" ),
  74. I18N_NOOP( "Des&tination" ),
  75. I18N_NOOP( "P&lugins" ),
  76. I18N_NOOP( "File&name" )
  77. };
  78. KPushButton* createButton( KGuiItem item, TQWidget* parent )
  79. {
  80. return new KPushButton( item.iconSet(), item.text(), parent );
  81. }
  82. KRenameImpl::KRenameImpl( TQWidget* p, KMenuBar* m, TQPushButton* finish )
  83. : DCOPObject( "KRename" ), TQObject( (TQObject*)p ),
  84. parent( p ), menuBar( m ), finishButton( finish )
  85. {
  86. m_hasCommandlineProfile = false;
  87. // Load Plugins
  88. plugin = PluginLoader::instance();
  89. helpDialogData = new HelpDialogData();
  90. // Maybe parent instead of 0 but might crash when switching from wizard to tab mode
  91. helpDialog = new HelpDialog( helpDialogData, NULL, NULL, false );
  92. m_switching = false;
  93. kapp->dcopClient()->registerAs( kapp->name() );
  94. }
  95. KRenameImpl::~KRenameImpl()
  96. {
  97. delete helpDialog;
  98. }
  99. int KRenameImpl::numRealTimePreview = -1;
  100. void KRenameImpl::setup( bool wizardmode )
  101. {
  102. parent->setCaption( "KRename" ); // "KRename by Dominik Seichter
  103. setupActions();
  104. setupPages();
  105. updateCount();
  106. connect( buttonAdd, TQT_SIGNAL( clicked() ), this, TQT_SLOT( addFile() ));
  107. connect( buttonRemoveAll, TQT_SIGNAL( clicked()), this, TQT_SLOT( clearList() ));
  108. connect( buttonRemove, TQT_SIGNAL( clicked()), this, TQT_SLOT( removeFile() ));
  109. connect( buttonHelp, TQT_SIGNAL( clicked()), this, TQT_SLOT( showTokenHelp() ));
  110. connect( finishButton, TQT_SIGNAL( clicked()), this, TQT_SLOT( start() ));
  111. connect( checkExtension, TQT_SIGNAL( clicked()), this, TQT_SLOT( enableControls() ));
  112. connect( optionRename, TQT_SIGNAL( clicked()), this, TQT_SLOT( enableControls() ));
  113. connect( optionMove, TQT_SIGNAL( clicked()), this, TQT_SLOT( enableControls() ));
  114. connect( optionCopy, TQT_SIGNAL( clicked()), this, TQT_SLOT( enableControls() ));
  115. connect( optionLink, TQT_SIGNAL( clicked()), this, TQT_SLOT( enableControls() ));
  116. connect( checkUndoScript, TQT_SIGNAL( clicked()), this, TQT_SLOT( enableControls() ));
  117. connect( fileList, TQT_SIGNAL( updateCount()), this, TQT_SLOT( updateCount() ));
  118. connect( fileList, TQT_SIGNAL( updatePreview()), this, TQT_SLOT( updatePreview() ));
  119. connect( fileList, TQT_SIGNAL( deletePressed()), this, TQT_SLOT( removeFile() ));
  120. connect( fileList, TQT_SIGNAL( addFiles()), this, TQT_SLOT( addFile() ));
  121. connect( buttonUp, TQT_SIGNAL( clicked()), fileList, TQT_SLOT( moveUp() ));
  122. connect( buttonDown, TQT_SIGNAL( clicked()), fileList, TQT_SLOT( moveDown() ));
  123. connect( buttonUp, TQT_SIGNAL( clicked()), this, TQT_SLOT( updatePreview() ));
  124. connect( buttonDown, TQT_SIGNAL( clicked()), this, TQT_SLOT( updatePreview() ));
  125. connect( buttonUp2, TQT_SIGNAL( clicked()), this, TQT_SLOT( moveUp() ));
  126. connect( buttonDown2, TQT_SIGNAL( clicked()), this, TQT_SLOT( moveDown() ));
  127. connect( buttonReplace, TQT_SIGNAL( clicked()), this, TQT_SLOT( replace() ));
  128. connect( buttonEasyReplace, TQT_SIGNAL( clicked()), this, TQT_SLOT( replace() ));
  129. connect( buttonCoord, TQT_SIGNAL( clicked()), this, TQT_SLOT( getCoordinates() ));
  130. connect( comboSort, TQT_SIGNAL( activated(int)), fileList, TQT_SLOT( setSorting(int) ));
  131. connect( filename, TQT_SIGNAL( delayedTextChanged() ), this, TQT_SLOT( updatePreview() ));
  132. connect( extemplate, TQT_SIGNAL( delayedTextChanged() ), this, TQT_SLOT( updatePreview() ));
  133. connect( checkExtension, TQT_SIGNAL( clicked()), this, TQT_SLOT( updatePreview() ));
  134. connect( comboExtension, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( updatePreview() ));
  135. connect( checkPreview, TQT_SIGNAL( clicked()), this, TQT_SLOT( toggleImagePreview() ));
  136. connect( preview, TQT_SIGNAL( itemChanged() ), this, TQT_SLOT( updatePreview() ));
  137. connect( preview, TQT_SIGNAL( removeItem(int) ), this, TQT_SLOT( removeFile(int) ));
  138. connect( preview, TQT_SIGNAL( addFile() ), this, TQT_SLOT( addFile() ));
  139. connect( undorequester, TQT_SIGNAL( urlSelected(const TQString &)), this, TQT_SLOT( changeUndoScriptName() ));
  140. connect( kapp, TQT_SIGNAL( aboutToQuit() ), this, TQT_SLOT( saveConfig() ) );
  141. connect( buttonMove, TQT_SIGNAL( clicked()), fileList, TQT_SLOT( moveMode() ));
  142. connect( checkName, TQT_SIGNAL( clicked()), this, TQT_SLOT( toggleName() ));
  143. connect( buttonNumber, TQT_SIGNAL( clicked()), this, TQT_SLOT( changeNumbers() ));
  144. // Load Configuration
  145. loadConfig();
  146. page_1->setEnabled( true );
  147. TDEApplication::restoreOverrideCursor();
  148. filename->setText( "$" ); // no i18n() ! ;)
  149. extemplate->setText( "$" );
  150. // do it now so that it can be overwritten by commandline args
  151. setWizardMode( wizardmode );
  152. parseCommandline();
  153. enableControls();
  154. }
  155. const TQString KRenameImpl::title( int index ) const
  156. {
  157. return i18n( pageTitle[index] );
  158. }
  159. void KRenameImpl::parseCommandline()
  160. {
  161. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  162. QCStringList optlist = args->getOptionList ( "r" );
  163. for (QCStringList::ConstIterator it=optlist.begin(); it!=optlist.end(); ++it)
  164. {
  165. KURL url;
  166. url.setPath( *it );
  167. fileList->addDir( url, "*", false, true, false );
  168. }
  169. //fileList->setUpdatesEnabled( false );
  170. //fileList->viewport()->setUpdatesEnabled( false );
  171. for( int i = 0; i < args->count(); i++)
  172. fileList->addFile( args->url( i ) );
  173. //fileList->viewport()->setUpdatesEnabled( true );
  174. //fileList->setUpdatesEnabled( true );
  175. // load the profile first, so that we do not overwrite other
  176. // commandline settings
  177. TQCString templ = args->getOption( "profile" );
  178. if( !templ.isEmpty() )
  179. {
  180. m_hasCommandlineProfile = true;
  181. ProfileManager::loadProfile( TQString( templ ), this );
  182. }
  183. if( !args->isSet( "previewitems" ) )
  184. numRealTimePreview = -1;
  185. else
  186. numRealTimePreview = TQString( args->getOption( "previewitems" ) ).toInt();
  187. templ = args->getOption( "template" );
  188. if( !templ.isEmpty() )
  189. filename->setText( templ );
  190. templ = args->getOption( "extension" );
  191. if( !templ.isEmpty() )
  192. {
  193. extemplate->setText( templ );
  194. checkExtension->setChecked( false );
  195. }
  196. templ = args->getOption( "copy" );
  197. if( !templ.isEmpty() )
  198. {
  199. urlrequester->setURL( templ );
  200. optionCopy->setChecked( true );
  201. }
  202. templ = args->getOption( "move" );
  203. if( !templ.isEmpty() )
  204. {
  205. urlrequester->setURL( templ );
  206. optionMove->setChecked( true );
  207. }
  208. QCStringList uselist = args->getOptionList ( "use-plugin" );
  209. if( !uselist.isEmpty() )
  210. {
  211. for(unsigned int i = 0; i < uselist.count(); i++ )
  212. uselist[i] = uselist[i].lower();
  213. TQPtrListIterator<PluginLoader::PluginLibrary> it( plugin->libs );
  214. while ( it.current() )
  215. {
  216. if( uselist.contains( (*it)->plugin->getName().lower().utf8() ) )
  217. (*it)->check->setChecked( true );
  218. ++it;
  219. }
  220. pluginHelpChanged();
  221. }
  222. bool startnow = args->isSet( "start" );
  223. // Free some memory
  224. args->clear();
  225. enableControls();
  226. updateCount();
  227. updatePreview();
  228. if( fileList->count() )
  229. {
  230. // we got already filenames over the commandline, so show directly the last
  231. // page of the wizard
  232. emit showPage( m_wizard ? 3 : 4 );
  233. }
  234. if( startnow )
  235. {
  236. // As file adding runs in a another trhread,
  237. // there might be adding in progress but not yet
  238. // all files in the list.
  239. // so let's wait for file adding to finish first
  240. // before starting.
  241. while( fileList->runningAddListeners() > 0 )
  242. kapp->processEvents();
  243. if( fileList->count() )
  244. // start renaming
  245. TQTimer::singleShot( 200, this, TQT_SLOT( start() ) );
  246. }
  247. }
  248. void KRenameImpl::setupActions()
  249. {
  250. TDEActionCollection* actionCollection = new TDEActionCollection( this );
  251. TDEPopupMenu* mnuExtra = new TDEPopupMenu( parent );
  252. TDEPopupMenu* mnuSettings = new TDEPopupMenu( parent );
  253. KHelpMenu* mnuHelp = new KHelpMenu( parent );
  254. menuBar->insertItem( i18n("E&xtras"), mnuExtra );
  255. mnuExtra->insertItem( i18n("&Profiles..."), this, TQT_SLOT( manageProfiles() ) );
  256. mnuExtra->insertSeparator();
  257. mnuExtra->insertItem( SmallIcon("edit-undo"), i18n("&Undo Old Renaming Action..."), this, TQT_SLOT( undo() ) );
  258. menuBar->insertItem( i18n("&Settings"), mnuSettings );
  259. menuBar->insertSeparator();
  260. menuBar->insertItem( i18n("&Help"), mnuHelp->menu() );
  261. TDEAction* prefAct = KStdAction::preferences( this, TQT_SLOT(preferences()), actionCollection );
  262. loadPlugins = new TDEAction( i18n("&Load TDE file plugins"), 0, this, TQT_SLOT( loadFilePlugins() ), actionCollection );
  263. TDEAction* reloadAct = new TDEAction( i18n("&Reload Plugin Data"), 0, this, TQT_SLOT( reloadFilePluginData() ), actionCollection );
  264. prefAct->plug( mnuSettings );
  265. mnuSettings->insertSeparator();
  266. loadPlugins->plug( mnuSettings );
  267. reloadAct->plug( mnuSettings );
  268. connect( mnuHelp, TQT_SIGNAL(showAboutApplication()), this, TQT_SLOT(about()));
  269. }
  270. void KRenameImpl::setupPages()
  271. {
  272. setupPage1();
  273. setupPage2();
  274. setupPage3();
  275. setupPage4();
  276. // Disable dirname ;)
  277. enableControls();
  278. }
  279. void KRenameImpl::setupPage1()
  280. {
  281. page_1 = new TQWidget( parent );
  282. pageLayout = new TQHBoxLayout( page_1, 11, 6 );
  283. Layout3 = new TQVBoxLayout( 0, 0, 6 );
  284. Layout4 = new TQHBoxLayout( 0, 0, 6 );
  285. Layout5 = new TQVBoxLayout( 0, 0, 6 );
  286. TQSpacerItem* spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
  287. TQSpacerItem* spacer2 = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
  288. fileList = new KMyListBox( page_1 );
  289. buttonAdd = new KPushButton( page_1 );
  290. buttonAdd->setText( i18n( "&Add..." ) );
  291. buttonRemove = new KPushButton( page_1 );
  292. buttonRemove->setText( i18n( "Re&move" ) );
  293. buttonRemoveAll = new KPushButton( page_1 );
  294. buttonRemoveAll->setText( i18n( "R&emove All" ) );
  295. comboSort = new KComboBox( false, page_1 );
  296. comboSort->insertItem( i18n("Sort: Unsorted") );
  297. comboSort->insertItem( i18n("Sort: Ascending") );
  298. comboSort->insertItem( i18n("Sort: Descending") );
  299. comboSort->insertItem( i18n("Sort: Random") );
  300. comboSort->insertItem( i18n("Sort: Numeric") );
  301. checkPreview = new TQCheckBox( page_1 );
  302. checkPreview->setText( i18n("&Preview") );
  303. labelCount = new TQLabel( page_1 );
  304. buttonUp = new KPushButton( page_1 );
  305. buttonUp->setPixmap( BarIcon( "1uparrow" ) );
  306. buttonDown = new KPushButton( page_1 );
  307. buttonDown->setPixmap( BarIcon( "1downarrow" ) );
  308. checkName = new TQCheckBox( page_1 );
  309. checkName->setText( i18n("&Display name") );
  310. buttonMove = new KPushButton( page_1 );
  311. buttonMove->setPixmap( BarIcon( "move" ) );
  312. Layout5->addWidget( buttonUp );
  313. Layout5->addWidget( buttonMove );
  314. Layout5->addWidget( buttonDown );
  315. Layout4->addLayout( Layout5 );
  316. Layout4->addItem( spacer2 );
  317. Layout3->addWidget( buttonAdd );
  318. Layout3->addWidget( buttonRemove );
  319. Layout3->addWidget( buttonRemoveAll );
  320. Layout3->addWidget( comboSort );
  321. Layout3->addWidget( checkPreview );
  322. Layout3->addWidget( checkName );
  323. Layout3->addWidget( labelCount );
  324. Layout3->addItem( spacer );
  325. Layout3->addLayout( Layout4 );
  326. Layout3->addItem( spacer );
  327. pageLayout->addWidget( fileList );
  328. pageLayout->setStretchFactor( fileList, 2 );
  329. pageLayout->addLayout( Layout3 );
  330. emit pageDone( page_1, i18n( pageTitle[0] ) );
  331. TQToolTip::add( buttonAdd, i18n( "Add one or more files or directories" ) );
  332. TQToolTip::add( buttonRemove, i18n( "Remove selected files" ) );
  333. TQToolTip::add( buttonRemoveAll, i18n( "Remove all files" ) );
  334. TQToolTip::add( checkPreview, i18n( "Enable/disable preview of pictures." ) );
  335. TQToolTip::add( labelCount, i18n( "Displays the number of files in the list." ) );
  336. TQToolTip::add( buttonUp, i18n( "Move selected items up" ));
  337. TQToolTip::add( buttonDown, i18n( "Move selected items down" ));
  338. TQToolTip::add( checkName, i18n( "Enable/disable display of file name." ) );
  339. TQToolTip::add( buttonMove, i18n( "Move selected items (select the new location with the mouse)" ));
  340. }
  341. void KRenameImpl::setupPage2()
  342. {
  343. page_2 = new TQWidget( parent );
  344. pageLayout_2 = new TQVBoxLayout( page_2, 6, 6 );
  345. TQSpacerItem* spacer_3 = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
  346. groupOptions = new TQButtonGroup( page_2 );
  347. groupOptions->setTitle( i18n( "O&ptions" ) );
  348. groupOptions->setColumnLayout(0, Qt::Vertical );
  349. groupOptions->layout()->setSpacing( 6 );
  350. groupOptions->layout()->setMargin( 11 );
  351. groupOptionsLayout = new TQVBoxLayout( groupOptions->layout() );
  352. groupOptionsLayout->setAlignment( TQt::AlignTop );
  353. optionRename = new TQRadioButton( groupOptions );
  354. optionRename->setText( i18n( "&Rename input files" ) );
  355. optionRename->setChecked( true );
  356. optionCopy = new TQRadioButton( groupOptions );
  357. optionCopy->setText( i18n( "Cop&y files to destination directory" ) );
  358. optionMove = new TQRadioButton( groupOptions );
  359. optionMove->setText( i18n( "&Move files to destination directory" ) );
  360. optionLink = new TQRadioButton( groupOptions );
  361. optionLink->setText( i18n("Create symbolic &links in destination directory") );
  362. dirname = new KMyHistoryCombo( false, groupOptions, "Path" );
  363. urlrequester = new KURLRequester( dirname, groupOptions );
  364. urlrequester->setMode( KFile::Directory | KFile::ExistingOnly );
  365. checkOverwrite = new TQCheckBox( groupOptions );
  366. checkOverwrite->setText( i18n( "&Overwrite existing files" ) );
  367. groupOptionsLayout->addWidget( optionRename );
  368. groupOptionsLayout->addWidget( optionCopy );
  369. groupOptionsLayout->addWidget( optionMove );
  370. groupOptionsLayout->addWidget( optionLink );
  371. groupOptionsLayout->addWidget( urlrequester );
  372. groupOptionsLayout->addItem( spacer_3 );
  373. groupOptionsLayout->addWidget( checkOverwrite );
  374. groupUndo = new TQVGroupBox( page_2 );
  375. groupUndo->setTitle( i18n("&Undo Renaming") );
  376. checkUndoScript = new TQCheckBox( i18n("&Create an undo script"), groupUndo );
  377. undorequester = new KURLRequester( groupUndo );
  378. undorequester->setEnabled( false );
  379. undorequester->setMode( KFile::File | KFile::LocalOnly );
  380. undorequester->setFilter( i18n("*.krename|KRename undo scripts (*.krename)\n"
  381. "*|All Files (*)") );
  382. undorequester->fileDialog()->setOperationMode( KFileDialog::Saving );
  383. pageLayout_2->addWidget( groupOptions );
  384. pageLayout_2->addWidget( groupUndo );
  385. pageLayout_2->addItem( spacer_3 );
  386. emit pageDone( page_2, i18n( pageTitle[1] ) );
  387. TQToolTip::add( optionRename, i18n( "Input files will be renamed." ) );
  388. TQToolTip::add( optionCopy, i18n( "Copies all files to the destination directory and renames them." ) );
  389. TQToolTip::add( optionMove, i18n( "Moves all files to the destination directory and renames them." ) );
  390. }
  391. void KRenameImpl::setupPage3()
  392. {
  393. page_3 = new KJanusWidget( parent, "janus", KJanusWidget::TreeList );
  394. page_3->setShowIconsInTreeList( true );
  395. page_3->setTreeListAutoResize( true );
  396. setupTab1();
  397. emit pageDone( page_3, i18n( pageTitle[2] ) );
  398. }
  399. void KRenameImpl::setupPage4()
  400. {
  401. page_4 = new TQWidget( parent );
  402. pageLayout_4 = new TQVBoxLayout( page_4, 11, 6 );
  403. fileTab = new TQWidgetStack( page_4 );
  404. setupFileTab1();
  405. setupFileTab2();
  406. Layout22 = new TQHBoxLayout( 0, 0, 6 );
  407. Layout23 = new TQVBoxLayout( 0, 0, 6 );
  408. preview = new KMyListView( &changes, fileList, page_4 );
  409. preview->setSorting( -1 );
  410. preview->addColumn( i18n( "Origin" ) );
  411. preview->addColumn( i18n( "Renamed" ) );
  412. buttonUp2 = new KPushButton( page_4 );
  413. buttonUp2->setPixmap( BarIcon( "1uparrow" ) );
  414. buttonDown2 = new KPushButton( page_4 );
  415. buttonDown2->setPixmap( BarIcon( "1downarrow" ) );
  416. TQSpacerItem* spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Expanding );
  417. Layout23->addItem( spacer );
  418. Layout23->addWidget( buttonUp2 );
  419. Layout23->addWidget( buttonDown2 );
  420. Layout23->addItem( spacer );
  421. Layout22->addWidget( preview );
  422. Layout22->addLayout( Layout23 );
  423. Layout22->setStretchFactor( preview, 2 );
  424. pageLayout_4->addWidget( fileTab );
  425. pageLayout_4->addLayout( Layout22 );
  426. emit pageDone( page_4, i18n( pageTitle[3] ) );
  427. TQToolTip::add( filename, i18n( "Add a template.<br>Example: <i>picture###</i>" ) );
  428. TQToolTip::add( extemplate, i18n( "Add a template for the file extension.<br>It behaves like the filename template.") );
  429. TQToolTip::add( checkExtension, i18n("Checking this checkbox is the same as setting the extension template to $"));
  430. TQToolTip::add( buttonUp2, i18n( "Move selected items up" ));
  431. TQToolTip::add( buttonDown2, i18n( "Move selected items down" ));
  432. TQToolTip::add( preview, i18n( "Double click on an item to modify it." ));
  433. TQToolTip::add( buttonHelp, i18n("Help Dialog with all tokens supported by KRename."));
  434. TQToolTip::add( buttonReplace, i18n("<qt>Find and replace characters or part string of the source filename in the destination filename.</qt>") );
  435. TQToolTip::add( buttonEasyReplace, i18n("<qt>Find and replace characters or part string of the source filename in the destination filename.</qt>") );
  436. TQToolTip::add( comboExtension, i18n("<qt>You can use \".gz\" and \".tar.gz\" as file extension of the file backup.tar.gz depending on this setting.</qt>") );
  437. }
  438. void KRenameImpl::setupFileTab1()
  439. {
  440. TQWidget* tab = new TQWidget( fileTab );
  441. labelTemplate = new TQLabel( tab );
  442. labelTemplate->setText( i18n( "&Template:" ) );
  443. filename = new KMyHistoryCombo( true, tab, "Template" );
  444. labelTemplate->setBuddy( filename );
  445. TQLabel* labelDot = new TQLabel( tab );
  446. labelDot->setText("<b>.</b>");
  447. extemplate = new KMyHistoryCombo( true, tab, "ExTemplate" );
  448. extemplate->setEnabled( FALSE );
  449. buttonHelp = new KPushButton( i18n("&Functions..."), tab );
  450. buttonHelp->setIconSet( SmallIcon("help") );
  451. checkExtension = new TQCheckBox( tab );
  452. checkExtension->setText( i18n( "&Use extension of the input file" ) );
  453. checkExtension->setChecked( TRUE );
  454. comboExtension = new KComboBox( false, tab );
  455. buttonReplace = new KPushButton( i18n("Find &and Replace..."), tab );
  456. buttonReplace->setIconSet( SmallIconSet("edit-find") );
  457. buttonNumber = new KPushButton( i18n("&Numbering..."), tab );
  458. buttonCoord = new KPushButton( i18n("&Insert Part of Filename..."), tab );
  459. helpDialog->setLineEdit( filename->lineEdit() );
  460. TQStringList help;
  461. help.append("$;;" + i18n("old filename") );
  462. help.append("%;;" + i18n("old filename converted to lower case") );
  463. help.append("&;;" + i18n("old filename converted to upper case") );
  464. help.append("*;;" + i18n("first letter of every word upper case") );
  465. help.append("[&1][%2-];;" + i18n("first letter of filename upper case") );
  466. help.append("#;;" + i18n("number (try also ##, ###, ... for leading zeros)") );
  467. help.append("#{0;1};;" + i18n("counter with custom start value 0 and custom stepping 1") );
  468. help.append("/;;" + i18n("create a subdirectory") );
  469. help.append("\\;;" + i18n("strip whitespaces leading and trailing") );
  470. help.append("[$x-y];;" + i18n("character x to y of old filename") );
  471. help.append("[$x;y];;" + i18n("y characters of old filename starting at x") );
  472. help.append("[$dirname];;" + i18n("insert name of directory") );
  473. help.append("[$dirname.];;" + i18n("insert name of parent directory") );
  474. help.append("[#length-0];;" + i18n("insert the length of the input filename") );
  475. helpDialogData->add( i18n("Built-in Functions:" ), &help, SmallIcon("krename"), true );
  476. help.clear();
  477. help.append( "\\$;;" + i18n("Insert '$'") );
  478. help.append( "\\%;;" + i18n("Insert '%'") );
  479. help.append( "\\&;;" + i18n("Insert '&'") );
  480. help.append( "\\*;;" + i18n("Insert '*'") );
  481. help.append( "\\/;;" + i18n("Insert '/'") );
  482. help.append( "\\\\;;" + i18n("Insert '\\\\'") );
  483. help.append( "\\[;;" + i18n("Insert '['") );
  484. help.append( "\\];;" + i18n("Insert ']'") );
  485. help.append( "\\#;;" + i18n("Insert '#'") );
  486. helpDialogData->add( i18n("Special Characters:" ), &help, SmallIcon("krename") );
  487. /*
  488. //TODO: FIX this tooltip
  489. TQToolTip::add( buttonHelp,
  490. i18n(
  491. "<b>$</b> old filename<br><b>%</b> old filename"
  492. " converted to lower case<br><b>&</b> old filename converted to upper case<br>"
  493. "<b>*</b> first letter of every word uppercase<br>"
  494. "<b>#</b> Adds a number to the filename (add more #'s for leading zeros)<br>"
  495. "<b>/</b> creates a subdirectory<br>"
  496. "<b>[$x-y]</b> Characters x to y of the old filename<br>"
  497. "<b>[%x-y]</b> Characters x to y converted to lower case"
  498. ) );
  499. */
  500. TQSpacerItem* spacer_9 = new TQSpacerItem( 200, 20, TQSizePolicy::Maximum, TQSizePolicy::Maximum );
  501. TQVBoxLayout* layout = new TQVBoxLayout( tab );
  502. TQHBoxLayout* Layout1 = new TQHBoxLayout( 0, 6, 6 );
  503. TQHBoxLayout* Layout2 = new TQHBoxLayout( 0, 6, 6 );
  504. TQHBoxLayout* ExtensionLayout = new TQHBoxLayout( 0, 6, 6 );
  505. Layout1->addWidget( labelTemplate );
  506. Layout1->addWidget( filename );
  507. Layout1->setStretchFactor( filename, 4 );
  508. Layout1->addWidget( labelDot );
  509. Layout1->addWidget( extemplate );
  510. Layout1->addWidget( buttonHelp );
  511. Layout2->addWidget( buttonReplace );
  512. Layout2->addWidget( buttonNumber );
  513. Layout2->addWidget( buttonCoord );
  514. Layout2->addItem( spacer_9 );
  515. ExtensionLayout->addWidget( checkExtension );
  516. ExtensionLayout->addItem( spacer_9 );
  517. ExtensionLayout->addWidget( new TQLabel( i18n("File extension starts at:"), tab ) );
  518. ExtensionLayout->addWidget( comboExtension );
  519. layout->addLayout( Layout1 );
  520. layout->addLayout( ExtensionLayout );
  521. layout->addLayout( Layout2 );
  522. layout->addItem( spacer_9 );
  523. fileTab->addWidget( tab, ID_TAB );
  524. }
  525. void KRenameImpl::setupFileTab2()
  526. {
  527. TQWidget* tab = new TQWidget( page_4 );
  528. TQHBoxLayout* layout = new TQHBoxLayout( tab, 6, 6 );
  529. TQVGroupBox* vgroup1 = new TQVGroupBox( i18n("&Filename"), tab );
  530. TQGrid* grid = new TQGrid( 4, vgroup1 );
  531. TQLabel* l = new TQLabel( i18n("&Prefix:"), grid );
  532. comboKRenamePrefix = new KComboBox( false, grid );
  533. comboPrefix = new KMyHistoryCombo( true, grid, "comboPrefix" );
  534. buttonEasy1 = new KPushButton( grid );
  535. l->setBuddy( comboPrefix );
  536. l = new TQLabel( i18n("&Suffix:"), grid );
  537. comboKRenameSuffix = new KComboBox( false, grid, "comboSuffix" );
  538. comboSuffix = new KMyHistoryCombo( true, grid );
  539. buttonEasy2 = new KPushButton( grid );
  540. l->setBuddy( comboSuffix );
  541. TQStringList comboItems;
  542. comboItems.append( i18n("Convert to lower case ") );
  543. comboItems.append( i18n("Convert to upper case") );
  544. comboItems.append( i18n("Capitalize") );
  545. l = new TQLabel( i18n("&Name:"), grid );
  546. comboKRenameFilename = new KComboBox( false, grid );
  547. comboKRenameFilename->insertItem( i18n("Use original name") );
  548. comboKRenameFilename->insertStringList( comboItems );
  549. comboKRenameFilename->insertItem( i18n("Custom name") );
  550. l->setBuddy( comboKRenameFilename );
  551. comboCustom = new KMyHistoryCombo( true, grid, "comboCustom" );
  552. buttonEasy3 = new KPushButton( grid );
  553. l = new TQLabel( i18n("&Extension:"), grid );
  554. comboKRenameExtension = new KComboBox( false, grid );
  555. comboKRenameExtension->insertItem( i18n("Use original extension") );
  556. comboKRenameExtension->insertStringList( comboItems );
  557. comboKRenameExtension->insertItem( i18n("Custom extension") );
  558. l->setBuddy( comboKRenameExtension );
  559. comboCustomExtension = new KMyHistoryCombo( true, grid, "comboCustomExtension" );
  560. buttonEasy4 = new KPushButton( grid );
  561. TQVBox* rightBox = new TQVBox( tab );
  562. TQVGroupBox* group = new TQVGroupBox( i18n("&Number" ), rightBox );
  563. spinStart = new KIntNumInput( group );
  564. spinStart->setLabel( i18n( "Start &index:" ), AlignLeft | AlignVCenter );
  565. spinNull = new KIntNumInput( spinStart, 1, group );
  566. spinNull->setLabel( i18n("&Number of digits:"), AlignLeft | AlignVCenter );
  567. spinNull->setRange( 1, 100, 1, false );
  568. buttonEasyReplace = new KPushButton( i18n("&Find and Replace..."), rightBox );
  569. buttonEasyReplace->setIconSet( SmallIconSet("edit-find") );
  570. layout->addWidget( vgroup1 );
  571. layout->addWidget( rightBox );
  572. comboKRenamePrefix->insertItem( "" );
  573. comboKRenamePrefix->insertItem( i18n("Number") );
  574. comboKRenamePrefix->insertItem( i18n("Date") );
  575. comboKRenameSuffix->insertItem( "" );
  576. comboKRenameSuffix->insertItem( i18n("Number") );
  577. comboKRenameSuffix->insertItem( i18n("Date") );
  578. enableControls();
  579. connect( comboPrefix, TQT_SIGNAL( textChanged( const TQString &)), this, TQT_SLOT( changed()));
  580. connect( comboSuffix, TQT_SIGNAL( textChanged( const TQString &)), this, TQT_SLOT( changed()));
  581. connect( comboKRenameFilename, TQT_SIGNAL( activated(int)), this, TQT_SLOT( changed()));
  582. connect( comboCustom, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SLOT( changed() ));
  583. connect( comboKRenamePrefix, TQT_SIGNAL(activated(int)), this, TQT_SLOT(changed()));
  584. connect( comboKRenameExtension, TQT_SIGNAL( activated(int)), this, TQT_SLOT( changed()));
  585. connect( comboCustomExtension, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SLOT( changed() ));
  586. connect( comboKRenameSuffix, TQT_SIGNAL(activated(int)), this, TQT_SLOT(changed()));
  587. connect( spinNull, TQT_SIGNAL( valueChanged(int) ), this, TQT_SLOT( changed() ));
  588. connect( spinStart, TQT_SIGNAL( valueChanged(int) ), this, TQT_SLOT( changed() ));
  589. buttonEasy1->setIconSet( SmallIcon("help") );
  590. buttonEasy2->setIconSet( SmallIcon("help") );
  591. buttonEasy3->setIconSet( SmallIcon("help") );
  592. buttonEasy4->setIconSet( SmallIcon("help") );
  593. buttonEasy1->setSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Maximum );
  594. buttonEasy2->setSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Maximum );
  595. buttonEasy3->setSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Maximum );
  596. buttonEasy4->setSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Maximum );
  597. const TQString easy_text( i18n("<qt>Insert a special KRename command which inserts file information into the filename.</qt>") );
  598. connect( buttonEasy1, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotEasy1() ) );
  599. connect( buttonEasy2, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotEasy2() ) );
  600. connect( buttonEasy3, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotEasy3() ) );
  601. connect( buttonEasy4, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotEasy4() ) );
  602. TQToolTip::add( buttonEasy1, easy_text );
  603. TQToolTip::add( buttonEasy2, easy_text );
  604. TQToolTip::add( buttonEasy3, easy_text );
  605. TQToolTip::add( buttonEasy4, easy_text );
  606. fileTab->addWidget( tab, ID_WIZARD );
  607. }
  608. TQString KRenameImpl::easyOptions( KComboBox* combo, KMyHistoryCombo* custom )
  609. {
  610. TQString t = TQString();
  611. if( combo->currentItem() == 0 )
  612. t = "$";
  613. else if( combo->currentItem() == 1 )
  614. t = "%";
  615. else if( combo->currentItem() == 2 )
  616. t = "&";
  617. else if( combo->currentItem() == 3 )
  618. t = "*";
  619. else if( combo->currentItem() == 4 )
  620. t = custom->text();
  621. return t;
  622. }
  623. void KRenameImpl::changed()
  624. {
  625. TQString t = easyOptions( comboKRenameFilename, comboCustom );
  626. t = comboPrefix->text() + t + comboSuffix->text();
  627. for( int i=0; i<spinNull->value();i++)
  628. {
  629. if( comboKRenamePrefix->currentItem() == 1 )
  630. t.prepend("#");
  631. if( comboKRenameSuffix->currentItem() == 1 )
  632. t.append("#");
  633. }
  634. if( comboKRenamePrefix->currentItem() == 2 )
  635. t.prepend( "[date]" );
  636. if( comboKRenameSuffix->currentItem() == 2 )
  637. t.append( "[date]" );
  638. TQString e = easyOptions( comboKRenameExtension, comboCustomExtension );
  639. bool update = false;
  640. update = ( counterStart() != spinStart->value() && t == fileNameTemplate() );
  641. setCounterStart( spinStart->value() );
  642. filename->setText( t );
  643. extemplate->setText( e );
  644. checkExtension->setChecked( (comboKRenameExtension->currentItem() == 0) );
  645. if( update )
  646. updatePre();
  647. enableControls();
  648. }
  649. void KRenameImpl::parseWizardMode()
  650. {
  651. /** This function is not very accrurate and
  652. * guesses most cases.
  653. * But it works pretty well and is IMHO enough for this
  654. * simple dialog.
  655. */
  656. TQString t = filename->text();
  657. spinNull->setValue( t.contains( "#" ) );
  658. if( t.startsWith( "[date]") )
  659. {
  660. t = t.right( t.length() - 6 );
  661. comboKRenamePrefix->setCurrentItem( 2 );
  662. }
  663. else if( t.startsWith( "#") )
  664. {
  665. while( t.startsWith( "#" ) )
  666. t = t.right( t.length() - 1 );
  667. comboKRenamePrefix->setCurrentItem( 1 );
  668. }
  669. if( t.endsWith( "[date]" ) )
  670. {
  671. t = t.left( t.length() - 6 );
  672. comboKRenameSuffix->setCurrentItem( 2 );
  673. }
  674. else if( t.endsWith( "#") )
  675. {
  676. while( t.endsWith( "#" ) )
  677. t = t.left( t.length() - 1 );
  678. comboKRenameSuffix->setCurrentItem( 1 );
  679. }
  680. int pos = -1;
  681. if( (pos = t.find( "$" )) > -1 )
  682. comboKRenameFilename->setCurrentItem( 0 );
  683. else if( (pos = t.find( "%" )) > -1 )
  684. comboKRenameFilename->setCurrentItem( 1 );
  685. else if( (pos = t.find( "&" )) > -1 )
  686. comboKRenameFilename->setCurrentItem( 2 );
  687. else if( (pos = t.find( "*" )) > -1 )
  688. comboKRenameFilename->setCurrentItem( 3 );
  689. else
  690. {
  691. comboKRenameFilename->setCurrentItem( 4 );
  692. comboCustom->setText( t );
  693. }
  694. if( pos > 0 )
  695. {
  696. comboPrefix->setText( t.left( pos ) );
  697. comboSuffix->setText( t.mid( pos + 1, t.length() - pos - 1) );
  698. }
  699. spinStart->setValue( m_index );
  700. }
  701. void KRenameImpl::setupTab1()
  702. {
  703. /*
  704. * Draw plugin user interfaces
  705. */
  706. TQFrame* parent;
  707. TQVBoxLayout* Layout;
  708. TQVBoxLayout* gLayout;
  709. TQGroupBox* g;
  710. TQWidget* page;
  711. /* strangely I do not have to delete this stuff
  712. * after plugins have been reloaded.
  713. * could cause a memory leak though
  714. */
  715. while( ( page = page_3->pageWidget( 0 ) ) )
  716. page_3->removePage( page );
  717. TQPtrListIterator<PluginLoader::PluginLibrary> it( plugin->libs ); // iterator for dict
  718. while ( it.current() ) {
  719. if( !(*it)->plugin->alwaysUsed() )
  720. {
  721. parent = page_3->addPage( (*it)->plugin->getName(), TQString(), (*it)->plugin->getIcon() );
  722. Layout = new TQVBoxLayout( parent, 11, 6, "Layout");
  723. g = new TQGroupBox( parent );
  724. gLayout = new TQVBoxLayout( g, 11, 6, "gLayout" );
  725. (*it)->check = new TQCheckBox( i18n("&Use this plugin"), parent );
  726. connect( (*it)->check, TQT_SIGNAL( clicked() ), this, TQT_SLOT( pluginHelpChanged() ) );
  727. connect( (*it)->plugin, TQT_SIGNAL( previewChanged( Plugin* ) ), this, TQT_SLOT( updatePluginPreview( Plugin* ) ) );
  728. Layout->addWidget( (*it)->check );
  729. (*it)->plugin->drawInterface( g, gLayout );
  730. Layout->addWidget( g );
  731. } else
  732. (*it)->plugin->addHelp( helpDialogData );
  733. ++it;
  734. }
  735. page_3->showPage( 1 );
  736. }
  737. void KRenameImpl::addFile()
  738. {
  739. bool auto_up = false;
  740. DSDirSelectDialog* dsd = new DSDirSelectDialog( parent );
  741. if( dsd->exec() == TQDialog::Accepted ) {
  742. KURL::List slist = dsd->selectedURLs();
  743. KURL::List::Iterator it = slist.begin();
  744. for ( ; it != slist.end(); ++it )
  745. {
  746. if( !fileList->isFile( *it, false ) )
  747. {
  748. if( dsd->onlyDirs() )
  749. fileList->addDirName( *it, dsd->currentFilter(), dsd->hidden(), dsd->recursively() );
  750. else
  751. fileList->addDir( *it, dsd->currentFilter(), dsd->hidden(), dsd->recursively(), dsd->dirs() );
  752. }
  753. else
  754. {
  755. fileList->addFile( *it, true );
  756. auto_up = true;
  757. }
  758. }
  759. if( auto_up )
  760. {
  761. updatePreview();
  762. updateCount();
  763. }
  764. }
  765. }
  766. void KRenameImpl::clearList()
  767. {
  768. fileList->clear();
  769. changes.clear();
  770. updateCount();
  771. updatePreview();
  772. }
  773. void KRenameImpl::removeFile()
  774. {
  775. unsigned int i = 0;
  776. do {
  777. if(fileList->isSelected( i ))
  778. removeFile( i );
  779. else
  780. i++;
  781. } while( i < fileList->count() );
  782. updateCount();
  783. updatePreview();
  784. }
  785. void KRenameImpl::removeFile( int index )
  786. {
  787. KURL url = fileList->url( index );
  788. fileList->removeItem( index );
  789. // we have this to display the add files url label when count() == 0
  790. fileList->positionLabel();
  791. // remove this file from changes, too
  792. for( unsigned int i = 0; i < changes.count(); i++ )
  793. if( changes[i].url == url )
  794. changes.remove( changes.at( i ) );
  795. updateCount();
  796. updatePreview();
  797. }
  798. void KRenameImpl::help()
  799. {
  800. kapp->invokeHelp();
  801. }
  802. void KRenameImpl::start()
  803. {
  804. if(!checkErrors())
  805. return;
  806. // Let the plugins check for erorrs
  807. TQPtrListIterator<PluginLoader::PluginLibrary> it( plugin->libs );
  808. while ( it.current() ) {
  809. if( (*it)->usePlugin && !(*it)->plugin->checkError() )
  810. return;
  811. ++it;
  812. }
  813. ProgressDialog* p = new ProgressDialog( 0, "p" );
  814. p->print(i18n("Starting conversion of %1 files.").arg(fileList->count()));
  815. // Save History
  816. dirname->saveSettings();
  817. filename->saveSettings();
  818. extemplate->saveSettings();
  819. TDEConfig * config = kapp->config();
  820. config->setGroup("FileExtension");
  821. config->writeEntry("FileExtensionCombo", comboExtension->currentItem() );
  822. // save the configuration
  823. saveConfig();
  824. b = new BatchRenamer();
  825. if( setupBatchRenamer( b, false ) )
  826. {
  827. p->show();
  828. parent->hide();
  829. b->processFiles( p, this );
  830. }
  831. // Memory leak!!! : ??
  832. //delete parent;
  833. }
  834. void KRenameImpl::enableControls()
  835. {
  836. comboCustom->setEnabled( comboKRenameFilename->currentItem() == 4 );
  837. comboCustomExtension->setEnabled( comboKRenameExtension->currentItem() == 4 );
  838. buttonEasy3->setEnabled( comboKRenameFilename->currentItem() == 4 );
  839. buttonEasy4->setEnabled( comboKRenameExtension->currentItem() == 4 );
  840. urlrequester->setEnabled( !optionRename->isChecked() );
  841. checkUndoScript->setEnabled( !optionCopy->isChecked() && !optionLink->isChecked() );
  842. undorequester->setEnabled( checkUndoScript->isChecked() && checkUndoScript->isEnabled() );
  843. extemplate->setEnabled( !checkExtension->isChecked() );
  844. loadPlugins->setEnabled( !plugin->filePluginsLoaded() );
  845. }
  846. bool KRenameImpl::checkErrors()
  847. {
  848. if( filename->text().isEmpty() ) {
  849. KMessageBox::sorry( parent, i18n("Specify a template to use for renaming files.") );
  850. return false;
  851. }
  852. if( dirname->text().isEmpty() && !optionRename->isChecked()) {
  853. KMessageBox::sorry( parent, i18n("Please give a destination directory !") );
  854. emit showPage( 2 );
  855. return false;
  856. }
  857. if( checkUndoScript->isChecked() && !optionCopy->isChecked() && undorequester->url().isEmpty() ) {
  858. KMessageBox::sorry( parent, i18n("Please give the name of the undo script!") );
  859. showPage( 2 );
  860. return false;
  861. }
  862. return true;
  863. }
  864. void KRenameImpl::updateCount()
  865. {
  866. labelCount->setText(i18n("Files: <b>%1</b>").arg(fileList->count()));
  867. buttonCoord->setEnabled( (bool)fileList->count() );
  868. buttonReplace->setEnabled( (bool)fileList->count() );
  869. buttonEasyReplace->setEnabled( (bool)fileList->count() );
  870. emit enableFinish( (bool)fileList->count() );
  871. buttonRemove->setEnabled( (bool)fileList->count() );
  872. buttonRemoveAll->setEnabled( (bool)fileList->count() );
  873. buttonMove->setEnabled( (bool)fileList->count() );
  874. buttonUp->setEnabled( (bool)fileList->count() );
  875. buttonUp2->setEnabled( (bool)fileList->count() );
  876. buttonDown->setEnabled( (bool)fileList->count() );
  877. buttonDown2->setEnabled( (bool)fileList->count() );
  878. updateDots();
  879. }
  880. void KRenameImpl::fillStructures( BatchRenamer* b, bool preview )
  881. {
  882. TQValueList<data> f;
  883. unsigned int max = (preview && KRenameImpl::numRealTimePreview > -1 ? KRenameImpl::numRealTimePreview : fileList->count());
  884. for( unsigned int i = 0; i < max; i++) {
  885. KURL url = fileList->url( i );
  886. TQFileInfo fi( url.path() );
  887. data fdata;
  888. fdata.dir = fileList->dir( i );
  889. if( !fdata.dir ) {
  890. splitFilename( &fi, &fdata.src.name, &fdata.src.extension );
  891. } else {
  892. fdata.src.name = BatchRenamer::findDirName( "dirname", url.path() );
  893. fdata.src.extension = "";
  894. }
  895. fdata.src.url = url;
  896. /* Let's do some error checking for files
  897. * called: file_xy.
  898. */
  899. if( url.path().right(1) == "." )
  900. // File ends with a dot
  901. fdata.src.name.append( "." );
  902. fdata.src.directory = fi.dirPath( true );
  903. if( fdata.src.directory.right(1) != "/" )
  904. fdata.src.directory.append("/");
  905. f.append( fdata );
  906. }
  907. /*
  908. * Tell plugins that they should fill their structure, too.
  909. * Check also which plugins should be used !
  910. */
  911. TQPtrListIterator<PluginLoader::PluginLibrary> it( plugin->libs );
  912. for( int z = 0; it.current(); ++it, z++ ) {
  913. if( (*it)->plugin->alwaysUsed() || ((*it)->check && (*it)->check->isChecked()) )
  914. (*it)->plugin->fillStructure();
  915. }
  916. b->setFiles( f );
  917. }
  918. void KRenameImpl::updatePre()
  919. {
  920. updatePreview();
  921. updateCount();
  922. toggleImagePreview();
  923. }
  924. void KRenameImpl::addFileOrDir( const TQString & name )
  925. {
  926. fileList->addFile( name, false );
  927. }
  928. void KRenameImpl::addFileOrDir( const KURL & name )
  929. {
  930. fileList->addFile( name, true );
  931. }
  932. bool KRenameImpl::setupBatchRenamer( BatchRenamer* b, bool preview )
  933. {
  934. b->setText( filename->text() );
  935. b->setExText( ( checkExtension->isChecked() ? TQString("$") : extemplate->text() ) );
  936. b->setIndex( m_index );
  937. b->setResetCounter( m_reset );
  938. b->setStep( m_step );
  939. b->setSkipList( skip );
  940. b->setReplaceList( rep );
  941. b->setChanges( changes );
  942. if( !preview ) {
  943. TQString url = urlrequester->url();
  944. if( url.right(1) != "/" )
  945. url.append( "/" );
  946. if (!TDEIO::NetAccess::exists(KURL(url), true, parent))
  947. {
  948. int m = KMessageBox::warningContinueCancel( parent, i18n("The directory %1 does not exist. "
  949. "KRename will create it for you.").arg( url ) );
  950. if( m == KMessageBox::Cancel )
  951. return false;
  952. int i = 0;
  953. TQString d = "/";
  954. TQString ds = TQString::null;
  955. for (ds = url.section("/", i, i, TQString::SectionSkipEmpty);
  956. !ds.isEmpty();
  957. i++, d.append("/"), ds = url.section("/", i, i, TQString::SectionSkipEmpty))
  958. {
  959. d += ds;
  960. if (!TDEIO::NetAccess::exists(d, false, parent) &&
  961. !TDEIO::NetAccess::mkdir(d, parent, -1))
  962. {
  963. tqDebug( "Can't create %s", d.latin1() );
  964. break;
  965. }
  966. }
  967. }
  968. b->setDirname( url );
  969. b->setOverwrite( checkOverwrite->isChecked() );
  970. b->setUndo( checkUndoScript->isChecked() && !optionCopy->isChecked() );
  971. if( checkUndoScript->isChecked() && !optionCopy->isChecked() )
  972. b->setUndoScript( undorequester->url() );
  973. b->setMode( currentRenameMode() );
  974. }
  975. fillStructures( b, preview );
  976. return true;
  977. }
  978. int KRenameImpl::currentRenameMode()
  979. {
  980. if( optionCopy->isChecked() )
  981. return COPY;
  982. else if( optionMove->isChecked() )
  983. return MOVE;
  984. else if( optionRename->isChecked() )
  985. return RENAME;
  986. else if( optionLink->isChecked() )
  987. return LINK;
  988. // prevent a compiler warning
  989. return RENAME;
  990. }
  991. void KRenameImpl::updatePluginPreview( Plugin* p )
  992. {
  993. TQPtrListIterator<PluginLoader::PluginLibrary> it( plugin->libs ); // iterator for dict
  994. while ( it.current() ) {
  995. if( (*it)->plugin == p && (*it)->usePlugin ) {
  996. updatePreview();
  997. return;
  998. }
  999. ++it;
  1000. }
  1001. }
  1002. void KRenameImpl::updatePreview()
  1003. {
  1004. // is there a number in the filename or extension
  1005. if( filename->text().contains( "#" ) || extemplate->text().contains( "#" ) )
  1006. buttonNumber->setEnabled( true );
  1007. else
  1008. buttonNumber->setEnabled( false );
  1009. if( filename->isEmpty() && extemplate->isEmpty() && !checkExtension->isChecked() )
  1010. return;
  1011. int h = preview->horizontalScrollBar()->value();
  1012. int v = preview->verticalScrollBar()->value();
  1013. preview->clear();
  1014. if( fileList->count() <= 0 )
  1015. return;
  1016. BatchRenamer b;
  1017. if( setupBatchRenamer( &b, true ) )
  1018. {
  1019. TDEApplication::setOverrideCursor( TQt::WaitCursor );
  1020. b.createPreview( preview );
  1021. TDEApplication::restoreOverrideCursor();
  1022. }
  1023. preview->horizontalScrollBar()->setValue( h );
  1024. preview->verticalScrollBar()->setValue( v );
  1025. }
  1026. void KRenameImpl::loadConfig()
  1027. {
  1028. TDEConfig* config = kapp->config();
  1029. config->setGroup("HistSize");
  1030. m_hist = config->readNumEntry("HistoryItems", 10 );
  1031. updateHist();
  1032. config->setGroup("GUISettings");
  1033. // Image Preview
  1034. checkPreview->setChecked(config->readBoolEntry("ImagePreview", false ));
  1035. fileList->setPreview( checkPreview->isChecked() );
  1036. m_index = config->readNumEntry("StartIndex", 1);
  1037. m_step = 1;
  1038. m_reset = false;
  1039. m_loadplugins = config->readBoolEntry("LoadFilePlugins", true );
  1040. m_autosize = config->readBoolEntry("ColumnAutosize", false );
  1041. checkName->setChecked(config->readBoolEntry("Name", false ));
  1042. fileList->setPreviewSize( config->readNumEntry("PreviewSize", 80) );
  1043. fileList->setName( checkName->isChecked() );
  1044. fileList->setSorting( config->readNumEntry("FileListSorting", KMyListBox::UNSORTED ) );
  1045. comboSort->setCurrentItem( fileList->sorting() );
  1046. CoordDialog::m_inversion = config->readBoolEntry("Inverse", false);
  1047. m_wizard = config->readBoolEntry( "GUIWizardMode", true );
  1048. int width = config->readNumEntry( "Width", parent->width() );
  1049. int height = config->readNumEntry( "Height", parent->height() );
  1050. if( config->readBoolEntry("Maximized", false ) ) {
  1051. parent->showMaximized();
  1052. } else {
  1053. parent->resize( width, height );
  1054. }
  1055. refreshColumnMode();
  1056. if( !m_autosize ) {
  1057. preview->setColumnWidth( 0,
  1058. config->readNumEntry("Column0", (width/2) - 40 ) );
  1059. preview->setColumnWidth( 1,
  1060. config->readNumEntry("Column1", (width/2) - 40 ) );
  1061. if( preview->columnWidth( 0 ) > (width/2) )
  1062. {
  1063. preview->setColumnWidth( 0, (width/2) - 40 );
  1064. preview->setColumnWidth( 1, (width/2) - 40 );
  1065. }
  1066. }
  1067. if( !checkPreview->isChecked() ) {
  1068. checkName->setChecked( true );
  1069. checkName->setEnabled( false );
  1070. }
  1071. //parent->show();
  1072. page_1->setEnabled( false );
  1073. TDEApplication::setOverrideCursor( TQt::WaitCursor );
  1074. plugin->loadPlugins( m_loadplugins );
  1075. setupTab1();
  1076. config->setGroup("GUISettings");
  1077. // File Extension
  1078. config->setGroup("FileExtension");
  1079. // default LAST DOT
  1080. comboExtension->setCurrentItem( config->readNumEntry("FileExtensionCombo", 1 ) );
  1081. }
  1082. void KRenameImpl::saveConfig()
  1083. {
  1084. TDEConfig* config = kapp->config();
  1085. config->setGroup("HistSize");
  1086. config->writeEntry("HistoryItems", m_hist );
  1087. config->setGroup("GUISettings");
  1088. config->writeEntry("firststart", false );
  1089. config->writeEntry("ImagePreview", checkPreview->isChecked() );
  1090. config->writeEntry("StartIndex", m_index );
  1091. config->writeEntry("Maximized", parent->isMaximized() );
  1092. config->writeEntry("Width", parent->width() );
  1093. config->writeEntry("Height", parent->height() );
  1094. config->writeEntry("XPos", parent->x() );
  1095. config->writeEntry("YPos", parent->y() );
  1096. config->writeEntry("LoadFilePlugins", m_loadplugins );
  1097. config->writeEntry("ColumnAutosize", m_autosize );
  1098. config->writeEntry("Name", checkName->isChecked() );
  1099. config->writeEntry("PreviewSize", fileList->getPreviewSize() );
  1100. config->writeEntry("Inverse", CoordDialog::m_inversion );
  1101. config->writeEntry("Column0", preview->columnWidth( 0 ) );
  1102. config->writeEntry("Column1", preview->columnWidth( 1 ) );
  1103. config->writeEntry("GUIWizardMode", m_wizard );
  1104. config->writeEntry("FileListSorting", fileList->sorting() );
  1105. config->sync();
  1106. }
  1107. void KRenameImpl::replace()
  1108. {
  1109. ReplaceDialog* r = new ReplaceDialog( rep, parent );
  1110. if( r->exec() == TQDialog::Accepted )
  1111. {
  1112. rep = r->getList();
  1113. updatePreview();
  1114. }
  1115. }
  1116. void KRenameImpl::toggleImagePreview()
  1117. {
  1118. TDEApplication::setOverrideCursor( TQt::waitCursor );
  1119. fileList->setPreview( checkPreview->isChecked() );
  1120. checkName->setEnabled( checkPreview->isChecked() );
  1121. if( !checkPreview->isChecked() )
  1122. checkName->setChecked( true );
  1123. fileList->setName( checkName->isChecked() );
  1124. TDEApplication::restoreOverrideCursor();
  1125. }
  1126. void KRenameImpl::toggleName()
  1127. {
  1128. TDEApplication::setOverrideCursor( TQt::waitCursor );
  1129. fileList->setName( checkName->isChecked() );
  1130. TDEApplication::restoreOverrideCursor();
  1131. }
  1132. void KRenameImpl::preferences()
  1133. {
  1134. ConfDialog* cd = new ConfDialog( parent, "cd" );
  1135. cd->setLoadPlugins( m_loadplugins );
  1136. cd->setThumbSize( fileList->getPreviewSize() );
  1137. cd->setAutosize( m_autosize );
  1138. cd->setHistoryItems( m_hist );
  1139. cd->setUseWizard( m_wizard );
  1140. if( cd->exec() == TQDialog::Accepted ) {
  1141. bool oldwiz = m_wizard;
  1142. m_loadplugins = cd->loadplugins();
  1143. m_autosize = cd->autosize();
  1144. m_hist = cd->historyItems();
  1145. m_wizard = cd->useWizard();
  1146. refreshColumnMode();
  1147. // fileList->setHiddenDirs( cd->hiddendir() );
  1148. if( fileList->getPreviewSize() != cd->thumbSize() ) {
  1149. fileList->setPreviewSize( cd->thumbSize() );
  1150. fileList->setPreview( checkPreview->isChecked() );
  1151. }
  1152. updatePreview();
  1153. updateHist();
  1154. if( oldwiz != m_wizard )
  1155. changeGUIMode();
  1156. }
  1157. }
  1158. void KRenameImpl::changeGUIMode()
  1159. {
  1160. /* GUI Mode was changed by the user */
  1161. saveConfig();
  1162. int x = parent->x();
  1163. int y = parent->y();
  1164. int w = parent->width();
  1165. int h = parent->height();
  1166. TQWidget* oldparent = parent;
  1167. TQWidget* krename = KRenameImpl::launch( TQRect( x, y, w, h ), TQStringList(), this, false );
  1168. m_switching = true;
  1169. oldparent->removeChild( this );
  1170. oldparent->hide();
  1171. krename->insertChild( this );
  1172. krename->show();
  1173. oldparent->close();
  1174. m_switching = false;
  1175. }
  1176. void KRenameImpl::moveUp()
  1177. {
  1178. TQListViewItem* item = preview->selectedItem();
  1179. if(item) {
  1180. int i = preview->itemIndex( item );
  1181. fileList->moveUp( i );
  1182. updatePreview();
  1183. if( (i-1) > 0 ) {
  1184. preview->setCurrentItem( preview->itemAtIndex( i-1 ) );
  1185. preview->ensureItemVisible( preview->itemAtIndex( i-1 ) );
  1186. }
  1187. }
  1188. }
  1189. void KRenameImpl::moveDown()
  1190. {
  1191. TQListViewItem* item = preview->selectedItem();
  1192. if(item) {
  1193. int i = preview->itemIndex( item );
  1194. fileList->moveDown( i );
  1195. updatePreview();
  1196. preview->setCurrentItem( preview->itemAtIndex( i+1 ) );
  1197. preview->ensureItemVisible( preview->itemAtIndex( i+1 ) );
  1198. }
  1199. }
  1200. void KRenameImpl::undo()
  1201. {
  1202. UndoDialog* u = new UndoDialog( parent );
  1203. u->exec();
  1204. delete u;
  1205. }
  1206. void KRenameImpl::changeUndoScriptName()
  1207. {
  1208. const char* EXTENSION = ".krename";
  1209. TQString script = undorequester->url();
  1210. if( script.right( 8 ) != EXTENSION ) {
  1211. script += EXTENSION;
  1212. undorequester->setURL( script );
  1213. }
  1214. }
  1215. void KRenameImpl::pluginHelpChanged()
  1216. {
  1217. TQPtrListIterator<PluginLoader::PluginLibrary> it( plugin->libs ); // iterator for dict
  1218. while ( it.current() ) {
  1219. if( !(*it)->plugin->alwaysUsed() ) {
  1220. (*it)->plugin->removeHelp( helpDialogData );
  1221. if( (*it)->check )
  1222. {
  1223. (*it)->usePlugin = (*it)->check->isChecked();
  1224. if( (*it)->check->isChecked() )
  1225. (*it)->plugin->addHelp( helpDialogData );
  1226. }
  1227. }
  1228. else
  1229. {
  1230. (*it)->plugin->removeHelp( helpDialogData );
  1231. (*it)->plugin->addHelp( helpDialogData );
  1232. }
  1233. ++it;
  1234. }
  1235. }
  1236. void KRenameImpl::showTokenHelp()
  1237. {
  1238. helpDialog->show();
  1239. }
  1240. void KRenameImpl::getCoordinates()
  1241. {
  1242. TQString name;
  1243. TQListViewItem* item = preview->selectedItem();
  1244. if( item )
  1245. name = item->text( 0 );
  1246. else {
  1247. item = preview->itemAtIndex( 0 );
  1248. if( item )
  1249. name = item->text( 0 );
  1250. }
  1251. TQFileInfo fi( name );
  1252. TQString extension;
  1253. splitFilename( &fi, &name, &extension );
  1254. CoordDialog* cd = new CoordDialog( name, parent );
  1255. if( cd->exec() == TQDialog::Accepted ) {
  1256. TQString t = filename->text();
  1257. if( filename->text() == "$" )
  1258. filename->setText( cd->coords() );
  1259. else {
  1260. t.insert( filename->cursorPosition(), cd->coords() );
  1261. filename->setText( t );
  1262. }
  1263. }
  1264. delete cd;
  1265. }
  1266. void KRenameImpl::splitFilename( TQFileInfo* fi, TQString* base, TQString* extension )
  1267. {
  1268. // first dot
  1269. if( comboExtension->currentItem() == 0 ) {
  1270. *base = fi->baseName();
  1271. *extension = fi->extension( true );
  1272. // last dot
  1273. } else if( comboExtension->currentItem() == 1 ) {
  1274. *extension = fi->extension( false );
  1275. if( !extension->isEmpty() )
  1276. *base = fi->fileName().left( fi->fileName().length() - extension->length() - 1 );
  1277. else
  1278. *base = fi->baseName();
  1279. } else {
  1280. // custom value
  1281. int dot = comboExtension->currentText().toInt();
  1282. TQString file = FileOperation::getName( fi->filePath() );
  1283. int p = 0;
  1284. if( !file.contains( "." ) || !dot || dot > file.contains( "." ) ) {
  1285. *base = file;
  1286. *extension = "";
  1287. return;
  1288. }
  1289. for( int i = 0; i < dot; i++ )
  1290. p = file.find( ".", p + 1 );
  1291. *base = file.left( p );
  1292. *extension = file.right( file.length() - p - 1 );
  1293. }
  1294. }
  1295. void KRenameImpl::refreshColumnMode()
  1296. {
  1297. if( !m_autosize ) {
  1298. preview->setColumnWidthMode( 0, TQListView::Manual );
  1299. preview->setColumnWidthMode( 1, TQListView::Manual );
  1300. } else {
  1301. preview->setColumnWidthMode( 0, TQListView::Maximum );
  1302. preview->setColumnWidthMode( 1, TQListView::Maximum );
  1303. }
  1304. }
  1305. void KRenameImpl::updateHist()
  1306. {
  1307. dirname->setMaxCount( m_hist );
  1308. filename->setMaxCount( m_hist );
  1309. extemplate->setMaxCount( m_hist );
  1310. }
  1311. void KRenameImpl::changeNumbers()
  1312. {
  1313. NumberDialog* nd = new NumberDialog( skip, parent );
  1314. nd->spinIndex->setValue( m_index );
  1315. nd->spinStep->setValue( m_step );
  1316. nd->checkResetCounter->setChecked( m_reset );
  1317. if( nd->exec() ) {
  1318. m_index = nd->spinIndex->value();
  1319. m_step = nd->spinStep->value();
  1320. skip = nd->getList();
  1321. m_reset = nd->checkResetCounter->isChecked();
  1322. updatePreview();
  1323. }
  1324. }
  1325. void KRenameImpl::about()
  1326. {
  1327. TDEAboutApplication * d = new TDEAboutApplication( kapp->aboutData(), parent );
  1328. d->show();
  1329. }
  1330. void KRenameImpl::setWizardMode( bool mode )
  1331. {
  1332. fileTab->raiseWidget( mode ? ID_WIZARD : ID_TAB );
  1333. // Maybe we should create a WidgetStack here, too
  1334. if( mode )
  1335. {
  1336. optionLink->hide();
  1337. if( optionLink->isChecked() )
  1338. {
  1339. optionLink->setChecked( false );
  1340. optionRename->setChecked( true );
  1341. enableControls();
  1342. }
  1343. }
  1344. else
  1345. optionLink->show();
  1346. if( mode )
  1347. parseWizardMode();
  1348. }
  1349. void KRenameImpl::changeParent( TQWidget* p, KMenuBar* m, TQPushButton* finish, TQRect r )
  1350. {
  1351. parent = p;
  1352. menuBar = m;
  1353. finishButton = finish;
  1354. connect( finishButton, TQT_SIGNAL( clicked()), this, TQT_SLOT( start() ));
  1355. if( !r.isNull() ) {
  1356. parent->resize( r.size() );
  1357. parent->move( r.x(), r.y() );
  1358. }
  1359. setupActions();
  1360. page_1->reparent( parent, TQPoint( 0, 0 ) );
  1361. page_2->reparent( parent, TQPoint( 0, 0 ) );
  1362. page_3->reparent( parent, TQPoint( 0, 0 ) );
  1363. page_4->reparent( parent, TQPoint( 0, 0 ) );
  1364. emit pageDone( page_1, i18n( pageTitle[0] ) );
  1365. emit pageDone( page_2, i18n( pageTitle[1] ) );
  1366. emit pageDone( page_3, i18n( pageTitle[2] ) );
  1367. emit pageDone( page_4, i18n( pageTitle[3] ) );
  1368. }
  1369. TQWidget* KRenameImpl::launch( TQRect rect, const KURL::List & list, KRenameImpl* impl, bool loadprofile )
  1370. {
  1371. TDEConfig* config = kapp->config();
  1372. config->setGroup("GUISettings");
  1373. bool firststart = config->readBoolEntry( "firststart", true );
  1374. bool wizardmode = config->readBoolEntry( "GUIWizardMode", false );
  1375. if( firststart ) {
  1376. /* start the GUI Mode selction dialog */
  1377. FirstStartDlg* fsd = new FirstStartDlg();
  1378. fsd->exec();
  1379. wizardmode = fsd->useWizard();
  1380. config->setGroup("GUISettings");
  1381. config->writeEntry( "firststart", false );
  1382. config->writeEntry( "GUIWizardMode", wizardmode );
  1383. config->sync();
  1384. }
  1385. TQWidget* w = NULL;
  1386. KRenameImpl* k = NULL;
  1387. if( wizardmode ) {
  1388. wizard* krename = new wizard( impl, rect );
  1389. k = krename->getKRename();
  1390. w = (TQWidget*)krename;
  1391. } else {
  1392. tabs* krename = new tabs( impl, rect );
  1393. k = krename->getKRename();
  1394. w = (TQWidget*)krename;
  1395. }
  1396. kapp->setMainWidget( w );
  1397. for( unsigned int i = 0; i < list.count(); i++ )
  1398. k->addFileOrDir( list[i] );
  1399. k->updatePre();
  1400. // it is time to load a default profile now (if the user has specified one)
  1401. if( loadprofile && !k->hasCommandlineProfile() && ProfileManager::hasDefaultProfile() )
  1402. ProfileManager::loadDefaultProfile( k );
  1403. else if ( !k->hasCommandlineProfile() )
  1404. w->show();
  1405. return w;
  1406. }
  1407. void KRenameImpl::updateDots()
  1408. {
  1409. int index = comboExtension->currentItem();
  1410. comboExtension->clear();
  1411. comboExtension->insertItem( i18n("First Dot") );
  1412. comboExtension->insertItem( i18n("Last Dot") );
  1413. unsigned int max = 0;
  1414. for( unsigned int i = 0; i < fileList->count(); i++ ) {
  1415. TQString name = fileList->url( i ).fileName();
  1416. int c = name.contains( "." );
  1417. max = ( c > (int)max ? c : (int)max);
  1418. }
  1419. for( unsigned int i = 2; i <= max; i++ )
  1420. comboExtension->insertItem( TQString::number( i ) );
  1421. comboExtension->setCurrentItem( index );
  1422. }
  1423. /** DCOP functions implementation
  1424. */
  1425. void KRenameImpl::setFileNameTemplate( const TQString & t )
  1426. {
  1427. filename->setText( t );
  1428. }
  1429. const TQString KRenameImpl::fileNameTemplate() const
  1430. {
  1431. return filename->text();
  1432. }
  1433. void KRenameImpl::setExtensionTemplate( const TQString & t )
  1434. {
  1435. extemplate->setText( t );
  1436. }
  1437. const TQString KRenameImpl::extensionTemplate() const
  1438. {
  1439. return extemplate->text();
  1440. }
  1441. void KRenameImpl::setUseExtension( bool b )
  1442. {
  1443. checkExtension->setChecked( b );
  1444. enableControls();
  1445. }
  1446. bool KRenameImpl::useExtension() const
  1447. {
  1448. return checkExtension->isChecked();
  1449. }
  1450. TQStringList KRenameImpl::tokens() const
  1451. {
  1452. return helpDialogData->tokens();
  1453. }
  1454. TQString KRenameImpl::parseString( const TQString & token, const TQString & string )
  1455. {
  1456. BatchRenamer b;
  1457. b.setIndex( 0 );
  1458. b.setStep( 0 );
  1459. return b.processString( token, string, 0 );
  1460. }
  1461. void KRenameImpl::addDir( const TQString & name, const TQString & filter, bool recursive, bool hidden, bool dirnames )
  1462. {
  1463. fileList->addDir( name, filter, hidden, recursive, dirnames );
  1464. }
  1465. void KRenameImpl::setCounterStart( int index )
  1466. {
  1467. m_index = index;
  1468. }
  1469. void KRenameImpl::loadFilePlugins()
  1470. {
  1471. TDEApplication::setOverrideCursor( TQt::WaitCursor );
  1472. plugin->loadPlugins( true );
  1473. TDEApplication::restoreOverrideCursor();
  1474. pluginHelpChanged();
  1475. enableControls();
  1476. }
  1477. void KRenameImpl::reloadFilePluginData()
  1478. {
  1479. plugin->clearCache();
  1480. updatePreview();
  1481. }
  1482. void KRenameImpl::manageProfiles()
  1483. {
  1484. ProfileDlg dlg( this, parent, "dlg" );
  1485. dlg.exec();
  1486. }
  1487. void KRenameImpl::getHelpDialogString( TQLineEdit* edit )
  1488. {
  1489. HelpDialog hdlg( helpDialogData, parent, "hdlg", true );
  1490. hdlg.setLineEdit( edit );
  1491. hdlg.updateHeadline();
  1492. hdlg.updateItems();
  1493. hdlg.exec();
  1494. }
  1495. void KRenameImpl::slotEasy1()
  1496. {
  1497. getHelpDialogString( comboPrefix->lineEdit() );
  1498. }
  1499. void KRenameImpl::slotEasy2()
  1500. {
  1501. getHelpDialogString( comboSuffix->lineEdit() );
  1502. }
  1503. void KRenameImpl::slotEasy3()
  1504. {
  1505. getHelpDialogString( comboCustom->lineEdit() );
  1506. }
  1507. void KRenameImpl::slotEasy4()
  1508. {
  1509. getHelpDialogString( comboCustomExtension->lineEdit() );
  1510. }
  1511. #include "krenameimpl.moc"