summaryrefslogtreecommitdiffstats
path: root/krename/kmylistview.cpp
blob: 885a4946329f41e895379582edb4fbd480b4474b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/***************************************************************************
                          kmylistview.cpp  -  description
                             -------------------
    begin                : Mit M� 27 2002
    copyright            : (C) 2002 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "kmylistview.h"
#include "myinputdialog.h"

// KDE includes
#include <kiconloader.h>
#include <klocale.h>
#include <kpopupmenu.h>
#include <krun.h>

KMyListView::KMyListView( TQValueList<manualchanges>* _changes, KMyListBox* _list, TQWidget* parent, const char* name )
    :TDEListView(parent, name )
{
    changes = _changes;
    list = _list;

    connect( this, TQT_SIGNAL( doubleClicked(TQListViewItem*, const TQPoint&, int) ),
        this, TQT_SLOT( changeItem(TQListViewItem*, const TQPoint&, int) ) );
    connect( this, TQT_SIGNAL( contextMenuRequested(TQListViewItem*, const TQPoint&, int) ),
        this, TQT_SLOT( showContext(TQListViewItem*, const TQPoint&, int) ) );
    setAllColumnsShowFocus( true );
}

KMyListView::~KMyListView()
{ }


void KMyListView::changeItem( TQListViewItem* item, const TQPoint&, int )
{
    if(!item) return;

    KURL url = list->url( itemIndex( item ) );

    bool revertenable = false;
    TQValueList<manualchanges>::iterator it;
    for ( it = changes->begin(); it != changes->end(); ++it )
        if( (*it).url == url ) {
            changes->remove( it );
            revertenable = true;
            break;
        }


    MyInputDialog i( item->text( 1 ), revertenable );
    i.setInputFilename( item->text( 0 ) );

    int code = i.exec();
    if( code == MyInputDialog::OK ) {
        manualchanges tmp = {
            url,
            i.filename()
        };

        changes->append( tmp );
        emit itemChanged();
    } else if( code == MyInputDialog::USE_KRENAME )
        emit itemChanged();
}

void KMyListView::showContext( TQListViewItem* item, const TQPoint& pos, int )
{
    TDEPopupMenu* menu = new TDEPopupMenu( this );
    if(item) {
        menu->insertTitle( list->text( itemIndex( item ) ), 0, 0 );
        menu->insertItem( i18n("&Change Filename Manually"), this, TQT_SLOT( changeCurrentItem() ), Key_F2 );
        menu->insertSeparator();
        menu->insertItem( BarIcon("exec"), i18n("Open"), this, TQT_SLOT( openCurrent() ) );
        menu->insertSeparator();
    }
    menu->insertItem( BarIcon("fileopen"), i18n("&Add..."), this, TQT_SLOT( addFiles() ) );
    if(item)
        menu->insertItem( BarIcon("editdelete"), i18n("&Remove"), this, TQT_SLOT( removeCurrentItem() ) );
            
    menu->popup( pos );
}

void KMyListView::removeCurrentItem()
{
    int index = itemIndex( currentItem() );
    emit removeItem( index );    
}

void KMyListView::addFiles()
{
    emit addFile();
}

void KMyListView::changeCurrentItem()
{
    changeItem( currentItem(), TQPoint( 0, 0 ), 0 );
}

void KMyListView::openCurrent()
{
    if( currentItem() )
        new KRun( list->text( itemIndex( currentItem() ) ) );
}

/////////////////////////////////////////////////////////////

KMyListViewItem::KMyListViewItem(TQListView *parent)
  : TDEListViewItem(parent)
{ }

KMyListViewItem::KMyListViewItem(TQListViewItem *parent)
  : TDEListViewItem(parent)
{ }

KMyListViewItem::KMyListViewItem(TQListView *parent, TQListViewItem *after)
  : TDEListViewItem(parent, after)
{ }

KMyListViewItem::KMyListViewItem(TQListViewItem *parent, TQListViewItem *after)
  : TDEListViewItem(parent, after)
{ }

KMyListViewItem::KMyListViewItem(bool m, TQListView *parent,
    TQString label1, TQString label2, TQString label3, TQString label4,
    TQString label5, TQString label6, TQString label7, TQString label8)
  : TDEListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
{
    modified = m;
}

KMyListViewItem::KMyListViewItem(bool m, TQListViewItem *parent,
    TQString label1, TQString label2, TQString label3, TQString label4,
    TQString label5, TQString label6, TQString label7, TQString label8)
  : TDEListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
{
    modified = m;
}

KMyListViewItem::KMyListViewItem(bool m, TQListView *parent, TQListViewItem *after,
    TQString label1, TQString label2, TQString label3, TQString label4,
    TQString label5, TQString label6, TQString label7, TQString label8)
  : TDEListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
{
    modified = m;
}

KMyListViewItem::KMyListViewItem(TQListViewItem *parent, TQListViewItem *after,
    TQString label1, TQString label2, TQString label3, TQString label4,
    TQString label5, TQString label6, TQString label7, TQString label8)
  : TDEListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
{ }

KMyListViewItem::~KMyListViewItem()
{ }

void KMyListViewItem::paintCell( TQPainter *p, const TQColorGroup &cg,
                                int column, int width, int alignment )
{
    TQColorGroup _cg( cg );
    TQColor c = _cg.text();
    if( modified )
        _cg.setColor( TQColorGroup::Text, TQt::red );

    TDEListViewItem::paintCell( p, _cg, column, width, alignment );
    _cg.setColor( TQColorGroup::Text, c );
}