KRename – powerful batch renamer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kmylistview.cpp 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /***************************************************************************
  2. kmylistview.cpp - description
  3. -------------------
  4. begin : Mit M� 27 2002
  5. copyright : (C) 2002 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 "kmylistview.h"
  17. #include "myinputdialog.h"
  18. // KDE includes
  19. #include <kiconloader.h>
  20. #include <tdelocale.h>
  21. #include <tdepopupmenu.h>
  22. #include <krun.h>
  23. KMyListView::KMyListView( TQValueList<manualchanges>* _changes, KMyListBox* _list, TQWidget* parent, const char* name )
  24. :TDEListView(parent, name )
  25. {
  26. changes = _changes;
  27. list = _list;
  28. connect( this, TQT_SIGNAL( doubleClicked(TQListViewItem*, const TQPoint&, int) ),
  29. this, TQT_SLOT( changeItem(TQListViewItem*, const TQPoint&, int) ) );
  30. connect( this, TQT_SIGNAL( contextMenuRequested(TQListViewItem*, const TQPoint&, int) ),
  31. this, TQT_SLOT( showContext(TQListViewItem*, const TQPoint&, int) ) );
  32. setAllColumnsShowFocus( true );
  33. }
  34. KMyListView::~KMyListView()
  35. { }
  36. void KMyListView::changeItem( TQListViewItem* item, const TQPoint&, int )
  37. {
  38. if(!item) return;
  39. KURL url = list->url( itemIndex( item ) );
  40. bool revertenable = false;
  41. TQValueList<manualchanges>::iterator it;
  42. for ( it = changes->begin(); it != changes->end(); ++it )
  43. if( (*it).url == url ) {
  44. changes->remove( it );
  45. revertenable = true;
  46. break;
  47. }
  48. MyInputDialog i( item->text( 1 ), revertenable );
  49. i.setInputFilename( item->text( 0 ) );
  50. int code = i.exec();
  51. if( code == MyInputDialog::OK ) {
  52. manualchanges tmp = {
  53. url,
  54. i.filename()
  55. };
  56. changes->append( tmp );
  57. emit itemChanged();
  58. } else if( code == MyInputDialog::USE_KRENAME )
  59. emit itemChanged();
  60. }
  61. void KMyListView::showContext( TQListViewItem* item, const TQPoint& pos, int )
  62. {
  63. TDEPopupMenu* menu = new TDEPopupMenu( this );
  64. if(item) {
  65. menu->insertTitle( list->text( itemIndex( item ) ), 0, 0 );
  66. menu->insertItem( i18n("&Change Filename Manually"), this, TQT_SLOT( changeCurrentItem() ), Key_F2 );
  67. menu->insertSeparator();
  68. menu->insertItem( BarIcon("application-x-executable"), i18n("Open"), this, TQT_SLOT( openCurrent() ) );
  69. menu->insertSeparator();
  70. }
  71. menu->insertItem( BarIcon("document-open"), i18n("&Add..."), this, TQT_SLOT( addFiles() ) );
  72. if(item)
  73. menu->insertItem( BarIcon("edit-delete"), i18n("&Remove"), this, TQT_SLOT( removeCurrentItem() ) );
  74. menu->popup( pos );
  75. }
  76. void KMyListView::removeCurrentItem()
  77. {
  78. int index = itemIndex( currentItem() );
  79. emit removeItem( index );
  80. }
  81. void KMyListView::addFiles()
  82. {
  83. emit addFile();
  84. }
  85. void KMyListView::changeCurrentItem()
  86. {
  87. changeItem( currentItem(), TQPoint( 0, 0 ), 0 );
  88. }
  89. void KMyListView::openCurrent()
  90. {
  91. if( currentItem() )
  92. new KRun( list->text( itemIndex( currentItem() ) ) );
  93. }
  94. /////////////////////////////////////////////////////////////
  95. KMyListViewItem::KMyListViewItem(TQListView *parent)
  96. : TDEListViewItem(parent)
  97. { }
  98. KMyListViewItem::KMyListViewItem(TQListViewItem *parent)
  99. : TDEListViewItem(parent)
  100. { }
  101. KMyListViewItem::KMyListViewItem(TQListView *parent, TQListViewItem *after)
  102. : TDEListViewItem(parent, after)
  103. { }
  104. KMyListViewItem::KMyListViewItem(TQListViewItem *parent, TQListViewItem *after)
  105. : TDEListViewItem(parent, after)
  106. { }
  107. KMyListViewItem::KMyListViewItem(bool m, TQListView *parent,
  108. TQString label1, TQString label2, TQString label3, TQString label4,
  109. TQString label5, TQString label6, TQString label7, TQString label8)
  110. : TDEListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
  111. {
  112. modified = m;
  113. }
  114. KMyListViewItem::KMyListViewItem(bool m, TQListViewItem *parent,
  115. TQString label1, TQString label2, TQString label3, TQString label4,
  116. TQString label5, TQString label6, TQString label7, TQString label8)
  117. : TDEListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
  118. {
  119. modified = m;
  120. }
  121. KMyListViewItem::KMyListViewItem(bool m, TQListView *parent, TQListViewItem *after,
  122. TQString label1, TQString label2, TQString label3, TQString label4,
  123. TQString label5, TQString label6, TQString label7, TQString label8)
  124. : TDEListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
  125. {
  126. modified = m;
  127. }
  128. KMyListViewItem::KMyListViewItem(TQListViewItem *parent, TQListViewItem *after,
  129. TQString label1, TQString label2, TQString label3, TQString label4,
  130. TQString label5, TQString label6, TQString label7, TQString label8)
  131. : TDEListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
  132. { }
  133. KMyListViewItem::~KMyListViewItem()
  134. { }
  135. void KMyListViewItem::paintCell( TQPainter *p, const TQColorGroup &cg,
  136. int column, int width, int alignment )
  137. {
  138. TQColorGroup _cg( cg );
  139. TQColor c = _cg.text();
  140. if( modified )
  141. _cg.setColor( TQColorGroup::Text, TQt::red );
  142. TDEListViewItem::paintCell( p, _cg, column, width, alignment );
  143. _cg.setColor( TQColorGroup::Text, c );
  144. }
  145. #include "kmylistview.moc"