~ubuntu-branches/ubuntu/intrepid/kid3/intrepid

« back to all changes in this revision

Viewing changes to kid3/filelist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michele Angrisano
  • Date: 2008-01-09 23:20:54 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080109232054-gtcjxz4ahdnzbt01
Tags: 0.10-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - debian/rules:
    + Use dh_icons instead dh_iconcache.
  - debian/control:
    + Update maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * \b Project: Kid3
6
6
 * \author Urs Fleisch
7
7
 * \date 9 Jan 2003
 
8
 *
 
9
 * Copyright (C) 2003-2007  Urs Fleisch
 
10
 *
 
11
 * This file is part of Kid3.
 
12
 *
 
13
 * Kid3 is free software; you can redistribute it and/or modify
 
14
 * it under the terms of the GNU General Public License as published by
 
15
 * the Free Software Foundation; either version 2 of the License, or
 
16
 * (at your option) any later version.
 
17
 *
 
18
 * Kid3 is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 * GNU General Public License for more details.
 
22
 *
 
23
 * You should have received a copy of the GNU General Public License
 
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
8
25
 */
9
26
 
10
27
#include "config.h"
16
33
#include <qurl.h>
17
34
#include <qregexp.h>
18
35
#if QT_VERSION >= 0x040000
19
 
#include <Q3PopupMenu>
20
 
#include <Q3Process>
21
 
#include <Q3Header>
 
36
#include <QMenu>
 
37
#include <QHeaderView>
22
38
#else
23
39
#include <qpopupmenu.h>
24
 
#include <qprocess.h>
25
40
#include <qheader.h>
26
41
#endif
27
42
#ifdef CONFIG_USE_KDE
 
43
#include <kdeversion.h>
28
44
#include <kmessagebox.h>
29
45
#endif
30
46
 
38
54
#include "mp3file.h"
39
55
#endif
40
56
#ifdef HAVE_VORBIS
41
 
#include "oggfile.h"
 
57
#include "oggfile.hpp"
42
58
#endif
43
59
#ifdef HAVE_FLAC
44
 
#include "flacfile.h"
 
60
#include "flacfile.hpp"
45
61
#endif
46
62
#ifdef HAVE_TAGLIB
47
63
#include "taglibfile.h"
49
65
 
50
66
/**
51
67
 * Constructor.
 
68
 * @param parent parent widget
52
69
 */
53
 
FileList::FileList(QWidget* parent, const char* name, Qt::WFlags f) :
54
 
        Q3ListView(parent, name, f), m_currentItemInDir(0), m_process(0)
 
70
FileList::FileList(QWidget* parent) :
 
71
#if QT_VERSION >= 0x040000
 
72
        QTreeWidget(parent), m_iterator(0),
 
73
#else
 
74
        QListView(parent),
 
75
#endif
 
76
        m_currentItemInDir(0), m_process(0)
55
77
{
 
78
#if QT_VERSION >= 0x040000
 
79
        setSelectionMode(ExtendedSelection);
 
80
        setSortingEnabled(false);
 
81
        setColumnCount(1);
 
82
        setContextMenuPolicy(Qt::CustomContextMenu);
 
83
        connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
 
84
                        this, SLOT(customContextMenu(const QPoint&)));
 
85
        connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)),
 
86
                                        this, SLOT(expandItem(QTreeWidgetItem*)));
 
87
        connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)),
 
88
                                        this, SLOT(collapseItem(QTreeWidgetItem*)));
 
89
        connect(this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
 
90
                                        this, SLOT(expandOrCollapseEmptyItem(QTreeWidgetItem*)));
 
91
#else
56
92
        setSelectionMode(Extended);
57
93
        setSorting(-1);
58
94
        addColumn("");
59
 
        header()->hide();
60
 
#if QT_VERSION >= 0x040000
61
 
        connect(this, SIGNAL(contextMenuRequested(Q3ListViewItem*, const QPoint&, int)),
62
 
                        this, SLOT(contextMenu(Q3ListViewItem*, const QPoint&)));
63
 
#else
64
95
        connect(this, SIGNAL(contextMenuRequested(QListViewItem*, const QPoint&, int)),
65
96
                        this, SLOT(contextMenu(QListViewItem*, const QPoint&)));
66
97
#endif
 
98
        header()->hide();
67
99
}
68
100
 
69
101
/**
72
104
FileList::~FileList()
73
105
{
74
106
        delete m_process;
 
107
#if QT_VERSION >= 0x040000
 
108
        delete m_iterator;
 
109
#endif
75
110
}
76
111
 
77
112
/**
80
115
 */
81
116
QSize FileList::sizeHint() const
82
117
{
83
 
        return QSize(fontMetrics().maxWidth() * 25, Q3ListView::sizeHint().height());
 
118
        return QSize(fontMetrics().maxWidth() * 25,
 
119
#if QT_VERSION >= 0x040000
 
120
                                                         QTreeWidget::sizeHint().height()
 
121
#else
 
122
                                                         QListView::sizeHint().height()
 
123
#endif
 
124
                );
84
125
}
85
126
 
86
127
/**
90
131
 *
91
132
 * @return next item with file.
92
133
 */
93
 
static FileListItem* getNextItemWithFile(Q3ListViewItemIterator& it)
 
134
static FileListItem* getNextItemWithFile(
 
135
#if QT_VERSION >= 0x040000
 
136
        QTreeWidgetItemIterator& it
 
137
#else
 
138
        QListViewItemIterator& it
 
139
#endif
 
140
        )
94
141
{
95
 
        Q3ListViewItem* lvItem;
96
 
        while ((lvItem = it.current()) != 0) {
 
142
#if QT_VERSION >= 0x040000
 
143
        QTreeWidgetItem* lvItem;
 
144
#else
 
145
        QListViewItem* lvItem;
 
146
#endif
 
147
        while ((lvItem = *it) != 0) {
97
148
                FileListItem* flItem = dynamic_cast<FileListItem*>(lvItem);
98
149
                if (flItem && flItem->getFile()) {
99
150
                        return flItem;
110
161
 */
111
162
FileListItem* FileList::first()
112
163
{
113
 
        m_iterator = Q3ListViewItemIterator(this);
 
164
#if QT_VERSION >= 0x040000
 
165
        delete m_iterator;
 
166
        if (topLevelItemCount() > 0) {
 
167
                m_iterator = new QTreeWidgetItemIterator(this);
 
168
                return getNextItemWithFile(*m_iterator);
 
169
        } else {
 
170
                m_iterator = 0;
 
171
                return 0;
 
172
        }
 
173
#else
 
174
        m_iterator = QListViewItemIterator(this);
114
175
        return getNextItemWithFile(m_iterator);
 
176
#endif
115
177
}
116
178
 
117
179
/**
121
183
 */
122
184
FileListItem* FileList::next()
123
185
{
124
 
        if (m_iterator.current()) {
 
186
#if QT_VERSION >= 0x040000
 
187
        if (m_iterator && **m_iterator) {
 
188
                ++*m_iterator;
 
189
                return getNextItemWithFile(*m_iterator);
 
190
        }
 
191
#else
 
192
        if (*m_iterator) {
125
193
                ++m_iterator;
126
194
                return getNextItemWithFile(m_iterator);
127
195
        }
 
196
#endif
128
197
        return 0;
129
198
}
130
199
 
135
204
 *
136
205
 * @return next item with file.
137
206
 */
138
 
static FileListItem* getNextItemWithFileInDir(Q3ListViewItem* lvItem)
 
207
static FileListItem* getNextItemWithFileInDir(
 
208
#if QT_VERSION >= 0x040000
 
209
        QTreeWidgetItem* lvItem
 
210
#else
 
211
        QListViewItem* lvItem
 
212
#endif
 
213
        )
139
214
{
140
215
        while (lvItem) {
141
216
                FileListItem* flItem = dynamic_cast<FileListItem*>(lvItem);
142
217
                if (flItem && flItem->getFile()) {
143
218
                        return flItem;
144
219
                }
 
220
#if QT_VERSION >= 0x040000
 
221
                QTreeWidgetItem* parent = lvItem->parent();
 
222
                QTreeWidgetItemIterator it(lvItem);
 
223
                lvItem = *(++it);
 
224
                if (lvItem && lvItem->parent() != parent) {
 
225
                        lvItem = 0;
 
226
                }
 
227
#else
145
228
                lvItem = lvItem->nextSibling();
 
229
#endif
146
230
        }
147
231
        return 0;
148
232
}
154
238
 */
155
239
FileListItem* FileList::firstInDir()
156
240
{
157
 
        // try to get the currently selected directory
158
 
        Q3ListViewItemIterator it(this, Q3ListViewItemIterator::Selected);
159
 
        FileListItem* item = dynamic_cast<FileListItem*>(it.current());
 
241
#if QT_VERSION >= 0x040000
 
242
        // try to get the currently selected directory
 
243
        if (topLevelItemCount() <= 0) {
 
244
                m_currentItemInDir = 0;
 
245
                return 0;
 
246
        }
 
247
        QTreeWidgetItemIterator it(this, QTreeWidgetItemIterator::Selected);
 
248
        FileListItem* item = dynamic_cast<FileListItem*>(*it);
 
249
        if (item &&
 
250
                 (item->getDirInfo() ||
 
251
                        (item->getFile() &&
 
252
                         (item = dynamic_cast<FileListItem*>(item->parent())) != 0))) {
 
253
                m_currentItemInDir =
 
254
                        getNextItemWithFileInDir(item->child(0));
 
255
        } else {
 
256
                // if not found, get the first child of the list view
 
257
                m_currentItemInDir =
 
258
                        getNextItemWithFileInDir(topLevelItem(0));
 
259
        }
 
260
 
 
261
        // if still not found, get the first file in the list view
 
262
        if (!m_currentItemInDir) {
 
263
                it = QTreeWidgetItemIterator(this);
 
264
                m_currentItemInDir = getNextItemWithFile(it);
 
265
        }
 
266
 
 
267
        return m_currentItemInDir;
 
268
#else
 
269
        // try to get the currently selected directory
 
270
        QListViewItemIterator it(this, QListViewItemIterator::Selected);
 
271
        FileListItem* item = dynamic_cast<FileListItem*>(*it);
160
272
        if (item &&
161
273
                 (item->getDirInfo() ||
162
274
                        (item->getFile() &&
171
283
 
172
284
        // if still not found, get the first file in the list view
173
285
        if (!m_currentItemInDir) {
174
 
                it = Q3ListViewItemIterator(this);
 
286
                it = QListViewItemIterator(this);
175
287
                m_currentItemInDir = getNextItemWithFile(it);
176
288
        }
177
289
 
178
290
        return m_currentItemInDir;
 
291
#endif
179
292
}
180
293
 
181
294
/**
186
299
FileListItem* FileList::nextInDir()
187
300
{
188
301
        if (m_currentItemInDir) {
 
302
#if QT_VERSION >= 0x040000
 
303
                QTreeWidgetItem* parent = m_currentItemInDir->parent();
 
304
                QTreeWidgetItemIterator it(m_currentItemInDir);
 
305
                QTreeWidgetItem* nextSibling = *(++it);
 
306
                if (nextSibling && nextSibling->parent() != parent) {
 
307
                        nextSibling = 0;
 
308
                }
 
309
                m_currentItemInDir = getNextItemWithFileInDir(nextSibling);
 
310
#else
189
311
                m_currentItemInDir =
190
312
                        getNextItemWithFileInDir(m_currentItemInDir->nextSibling());
 
313
#endif
191
314
        }
192
315
        return m_currentItemInDir;
193
316
}
200
323
int FileList::numFilesSelected()
201
324
{
202
325
        int numSelected = 0;
203
 
        Q3ListViewItemIterator it(this, Q3ListViewItemIterator::Selected);
 
326
#if QT_VERSION >= 0x040000
 
327
        if (topLevelItemCount() <= 0) {
 
328
                return 0;
 
329
        }
 
330
        QTreeWidgetItemIterator it(this, QTreeWidgetItemIterator::Selected);
 
331
#else
 
332
        QListViewItemIterator it(this, QListViewItemIterator::Selected);
 
333
#endif
204
334
        FileListItem* item;
205
335
        while ((item = getNextItemWithFile(it)) != 0) {
206
336
                ++numSelected;
214
344
 */
215
345
void FileList::selectNextFile()
216
346
{
217
 
        Q3ListViewItem* item = currentItem();
 
347
#if QT_VERSION >= 0x040000
 
348
        QTreeWidgetItem* item = currentItem();
 
349
        if (item && (item = *(++QTreeWidgetItemIterator(item))) != 0) {
 
350
                clearSelection();
 
351
                setCurrentItem(item);
 
352
                setItemSelected(item, true);
 
353
        }
 
354
#else
 
355
        QListViewItem* item = currentItem();
218
356
        if (item && (item = item->itemBelow()) != 0) {
219
357
                clearSelection();
220
358
                setCurrentItem(item);
221
 
                setSelected(item, true);                
 
359
                setSelected(item, true);
222
360
        }
 
361
#endif
223
362
}
224
363
 
225
364
/**
227
366
 */
228
367
void FileList::selectPreviousFile()
229
368
{
230
 
        Q3ListViewItem* item = currentItem();
 
369
#if QT_VERSION >= 0x040000
 
370
        QTreeWidgetItem* item = currentItem();
 
371
        if (item && (item = *(--QTreeWidgetItemIterator(item))) != 0) {
 
372
                clearSelection();
 
373
                setCurrentItem(item);
 
374
                setItemSelected(item, true);
 
375
        }
 
376
#else
 
377
        QListViewItem* item = currentItem();
231
378
        if (item && (item = item->itemAbove()) != 0) {
232
379
                clearSelection();
233
380
                setCurrentItem(item);
234
 
                setSelected(item, true);                
 
381
                setSelected(item, true);
235
382
        }
236
 
}
237
 
 
238
 
/**
239
 
 * Create a TaggedFile subclass depending on the file extension.
240
 
 *
241
 
 * @param di directory information
242
 
 * @param fn filename
243
 
 *
244
 
 * @return tagged file, 0 if no type found.
245
 
 */
246
 
TaggedFile* FileList::createTaggedFile(const DirInfo* di, const QString& fn)
247
 
{
248
 
        TaggedFile* taggedFile = 0;
249
 
#ifdef HAVE_VORBIS
250
 
        if (fn.right(4).lower() == ".ogg")
251
 
                taggedFile = new OggFile(di, fn);
252
 
        else
253
 
#endif
254
 
#ifdef HAVE_FLAC
255
 
                if (fn.right(5).lower() == ".flac")
256
 
                        taggedFile = new FlacFile(di, fn);
257
 
                else
258
 
#endif
259
 
#ifdef HAVE_ID3LIB
260
 
                        if (fn.right(4).lower() == ".mp3"
261
 
#ifdef HAVE_TAGLIB
262
 
                        && Kid3App::s_miscCfg.m_id3v2Version != MiscConfig::ID3v2_4_0
263
 
#endif
264
 
                )
265
 
                taggedFile = new Mp3File(di, fn);
266
 
                        else
267
 
#endif
268
 
#ifdef HAVE_TAGLIB
269
 
                taggedFile = new TagLibFile(di, fn);
270
 
#else
271
 
        ;
272
 
#endif
273
 
        return taggedFile;
 
383
#endif
274
384
}
275
385
 
276
386
/**
279
389
 * @param dirInfo  information  about directory
280
390
 * @param item     parent directory item or 0 if top-level
281
391
 * @param listView parent list view if top-level, else 0
 
392
 * @param fileName name of file to select (optional, else empty)
282
393
 */
283
394
void FileList::readSubDirectory(DirInfo* dirInfo, FileListItem* item,
284
 
                                                                                                                                FileList* listView)
 
395
                                                                                                                                FileList* listView, const QString& fileName)
285
396
{
286
397
        if (!dirInfo) return;
287
398
        QString dirname = dirInfo->getDirname();
289
400
        FileListItem* last = 0;
290
401
        QDir dir(dirname);
291
402
        QStringList dirContents = dir.entryList(QDir::Dirs) +
 
403
#if QT_VERSION >= 0x040000
 
404
                dir.entryList(Kid3App::s_miscCfg.m_nameFilter.split(' '), QDir::Files);
 
405
#else
292
406
                dir.entryList(Kid3App::s_miscCfg.m_nameFilter, QDir::Files);
 
407
#endif
293
408
        for (QStringList::Iterator it = dirContents.begin();
294
409
                         it != dirContents.end(); ++it) {
295
410
                QString filename = dirname + QDir::separator() + *it;
296
411
                if (!QFileInfo(filename).isDir()) {
297
 
                        TaggedFile* taggedFile = createTaggedFile(dirInfo, *it);
 
412
                        TaggedFile* taggedFile = TaggedFile::createFile(dirInfo, *it);
298
413
                        if (taggedFile) {
299
414
                                if (item) {
300
415
                                        last = new FileListItem(item, last, taggedFile);
301
416
                                } else if (listView) {
302
417
                                        last = new FileListItem(listView, last, taggedFile);
303
418
                                }
 
419
                                if (!fileName.isEmpty() && fileName == *it && last && listView) {
 
420
                                        listView->clearSelection();
 
421
                                        listView->setCurrentItem(last);
 
422
#if QT_VERSION >= 0x040000
 
423
                                        listView->setItemSelected(last, true);
 
424
#else
 
425
                                        listView->setSelected(last, true);
 
426
                                        listView->ensureItemVisible(last);
 
427
#endif
 
428
                                }
304
429
                                ++numFiles;
305
430
                        }
306
431
                } else {
322
447
/**
323
448
 * Fill the filelist with the files found in a directory.
324
449
 *
325
 
 * @param name path of directory
 
450
 * @param name     path of directory
 
451
 * @param fileName name of file to select (optional, else empty)
 
452
 *
326
453
 * @return false if name is not directory path, else true.
327
454
 */
328
 
bool FileList::readDir(const QString& name)
 
455
bool FileList::readDir(const QString& name, const QString& fileName)
329
456
{
330
457
        QFileInfo file(name);
331
458
        if(file.isDir()) {
332
459
                clear();
333
 
                m_dirInfo.setDirname(file.absFilePath());
334
 
                readSubDirectory(&m_dirInfo, 0, this);
 
460
                m_dirInfo.setDirname(file.QCM_absoluteFilePath());
 
461
                readSubDirectory(&m_dirInfo, 0, this, fileName);
335
462
                return true;
336
463
        }
337
464
        return false;
353
480
                item->updateIcons();
354
481
                item = next();
355
482
        }
 
483
#if QT_VERSION >= 0x040000
 
484
        update();
 
485
#else
356
486
        triggerUpdate();
 
487
#endif
357
488
        return modified;
358
489
}
359
490
 
363
494
 * @param item list box item
364
495
 * @param pos  position where context menu is drawn on screen
365
496
 */
366
 
void FileList::contextMenu(Q3ListViewItem* item, const QPoint& pos)
 
497
void FileList::contextMenu(
 
498
#if QT_VERSION >= 0x040000
 
499
        QTreeWidgetItem* item,
 
500
#else
 
501
        QListViewItem* item,
 
502
#endif
 
503
        const QPoint& pos)
367
504
{
368
505
        if (item && !Kid3App::s_miscCfg.m_contextMenuCommands.empty()) {
369
 
                Q3PopupMenu menu(this);
 
506
#if QT_VERSION >= 0x040000
 
507
                QMenu menu(this);
 
508
                menu.addAction(i18n("&Rename"), this, SLOT(renameFile()));
 
509
                menu.addAction(i18n("&Delete"), this, SLOT(deleteFile()));
 
510
                int id = 0;
 
511
                for (MiscConfig::MenuCommandList::const_iterator
 
512
                                         it = Kid3App::s_miscCfg.m_contextMenuCommands.begin();
 
513
                                 it != Kid3App::s_miscCfg.m_contextMenuCommands.end();
 
514
                                 ++it) {
 
515
                        menu.addAction((*it).getName());
 
516
                        ++id;
 
517
                }
 
518
                connect(&menu, SIGNAL(triggered(QAction*)), this, SLOT(executeAction(QAction*)));
 
519
#else
 
520
                QPopupMenu menu(this);
370
521
                menu.insertItem(i18n("&Rename"), this, SLOT(renameFile()));
371
522
                menu.insertItem(i18n("&Delete"), this, SLOT(deleteFile()));
372
523
                int id = 0;
373
 
                for (Q3ValueList<MiscConfig::MenuCommand>::const_iterator
 
524
                for (MiscConfig::MenuCommandList::const_iterator
374
525
                                         it = Kid3App::s_miscCfg.m_contextMenuCommands.begin();
375
526
                                 it != Kid3App::s_miscCfg.m_contextMenuCommands.end();
376
527
                                 ++it) {
377
528
                        menu.insertItem((*it).getName(), this, SLOT(executeContextCommand(int)), 0, id);
378
529
                        ++id;
379
530
                }
 
531
#endif
380
532
                menu.setMouseTracking(true);
381
533
                menu.exec(pos);
382
534
        }
430
582
        for (QStringList::const_iterator it = format.begin();
431
583
                         it != format.end();
432
584
                         ++it) {
433
 
                if ((*it).find('%') == -1) {
 
585
                if ((*it).QCM_indexOf('%') == -1) {
434
586
                        fmt.push_back(*it);
435
587
                } else {
436
588
                        if (*it == "%F") {
439
591
                        } else if (*it == "%uF") {
440
592
                                // list of URLs or URL
441
593
                                QUrl url;
442
 
                                url.setProtocol("file");
 
594
                                url.QCM_setScheme("file");
443
595
                                for (QStringList::const_iterator fit = files.begin();
444
596
                                                 fit != files.end();
445
597
                                                 ++fit) {
446
 
                                        url.setFileName(*fit);
447
 
                                        fmt.push_back(url.toString(
448
 
#if QT_VERSION < 0x040000
449
 
                                                                                                        true
450
 
#endif
451
 
                                                                                                        ));
 
598
                                        url.QCM_setPath(*fit);
 
599
                                        fmt.push_back(url.toString());
452
600
                                }
453
601
                        } else {
454
602
                                const int numTagCodes = 3;
459
607
                                        tagStr[1] = tagStr[0];
460
608
                                        tagStr[2] = Kid3App::s_miscCfg.m_browser;
461
609
                                        if (!dirInfo) {
462
 
                                                int sepPos = tagStr[1].findRev('/');
 
610
                                                int sepPos = tagStr[1].QCM_lastIndexOf('/');
463
611
                                                if (sepPos < 0) {
464
 
                                                        sepPos = tagStr[1].findRev(QDir::separator());
 
612
                                                        sepPos = tagStr[1].QCM_lastIndexOf(QDir::separator());
465
613
                                                }
466
614
                                                if (sepPos >= 0) {
467
615
                                                        tagStr[1].truncate(sepPos);
471
619
                                QString str = StandardTags::replacePercentCodes(*it, tagCode, tagStr, numTagCodes);
472
620
 
473
621
                                int ufPos;
474
 
                                if ((ufPos = str.find("%uf")) != -1 && !files.empty()) {
 
622
                                if ((ufPos = str.QCM_indexOf("%uf")) != -1 && !files.empty()) {
475
623
                                        QUrl url;
476
 
                                        url.setProtocol("file");
477
 
                                        url.setFileName(files.front());
478
 
                                        str.replace(ufPos, 3, url.toString(
479
 
#if QT_VERSION < 0x040000
480
 
                                                                                                true
481
 
#endif
482
 
                                                                                                ));
 
624
                                        url.QCM_setScheme("file");
 
625
                                        url.QCM_setPath(files.front());
 
626
                                        str.replace(ufPos, 3, url.toString());
483
627
                                }
484
628
 
485
629
                                if (firstSelectedItem) {
533
677
                                args.push_back(str);
534
678
                                end = begin;
535
679
                        } else {
536
 
                                end = cmd.find(' ', begin + 1);
 
680
                                end = cmd.QCM_indexOf(' ', begin + 1);
537
681
                                if (end == -1) end = len;
538
682
                                args.push_back(cmd.mid(begin, end - begin));
539
683
                        }
552
696
}
553
697
 
554
698
/**
 
699
 * Execute a context menu action.
 
700
 *
 
701
 * @param action action of selected menu
 
702
 */
 
703
#if QT_VERSION >= 0x040000
 
704
void FileList::executeAction(QAction* action)
 
705
{
 
706
        if (action) {
 
707
                QString name = action->text();
 
708
                int id = 0;
 
709
                for (MiscConfig::MenuCommandList::const_iterator
 
710
                                         it = Kid3App::s_miscCfg.m_contextMenuCommands.begin();
 
711
                                 it != Kid3App::s_miscCfg.m_contextMenuCommands.end();
 
712
                                 ++it) {
 
713
                        if (name == (*it).getName()) {
 
714
                                executeContextCommand(id);
 
715
                                break;
 
716
                        }
 
717
                        ++id;
 
718
                }
 
719
        }
 
720
}
 
721
#else
 
722
void FileList::executeAction(QAction*) {}
 
723
#endif
 
724
 
 
725
/**
555
726
 * Rename the selected file(s).
556
727
 */
557
728
void FileList::renameFile()
564
735
                if (item->isInSelection() &&
565
736
                                (taggedFile = item->getFile()) != 0) {
566
737
                        bool ok;
567
 
                        QString newFileName = QInputDialog::getText(
 
738
                        QString newFileName = QInputDialog::QCM_getText(
 
739
                                this,
568
740
                                i18n("Rename File"),
569
741
                                i18n("Enter new file name:"),
570
 
                                QLineEdit::Normal, taggedFile->getFilename(), &ok, this);
 
742
                                QLineEdit::Normal, taggedFile->getFilename(), &ok);
571
743
                        if (ok && !newFileName.isEmpty()) {
572
744
                                if (taggedFile->isChanged()) {
573
745
                                        taggedFile->setFilename(newFileName);
582
754
                                        item->setFile(0);
583
755
                                        if (QDir().rename(absFilename, newPath)) {
584
756
                                                TaggedFile* newTaggedFile =
585
 
                                                        createTaggedFile(dirInfo, newFileName);
 
757
                                                        TaggedFile::createFile(dirInfo, newFileName);
586
758
                                                if (newTaggedFile) {
587
759
                                                        item->setFile(newTaggedFile);
588
760
                                                        fileRenamed = true;
589
761
                                                }
590
762
                                        } else {
591
 
                                                item->setFile(createTaggedFile(dirInfo, filename));
 
763
                                                item->setFile(TaggedFile::createFile(dirInfo, filename));
592
764
                                                QMessageBox::warning(
593
765
                                                        0, i18n("File Error"),
594
766
                                                        i18n("Error while renaming:\n") +
612
784
                        (dirInfo = item->getDirInfo()) != 0) {
613
785
                QFileInfo fi(dirInfo->getDirname());
614
786
                bool ok;
615
 
                QString newDirName = QInputDialog::getText(
 
787
                QString newDirName = QInputDialog::QCM_getText(
 
788
                        this,
616
789
                        i18n("Rename Directory"),
617
790
                        i18n("Enter new directory name:"),
618
 
                        QLineEdit::Normal, fi.fileName(), &ok, this);
 
791
                        QLineEdit::Normal, fi.fileName(), &ok);
619
792
                if (ok && !newDirName.isEmpty()) {
 
793
#if QT_VERSION >= 0x040000
 
794
                        QString newPath = fi.dir().path() + '/' + newDirName;
 
795
#else
620
796
                        QString newPath = fi.dirPath() + '/' + newDirName;
 
797
#endif
621
798
                        if (QDir().rename(dirInfo->getDirname(), newPath)) {
622
799
                                item->setDirName(newPath);
623
800
                        } else {
650
827
#ifdef CONFIG_USE_KDE
651
828
                if (KMessageBox::warningContinueCancelList(
652
829
                                        this,
 
830
#if KDE_VERSION >= 0x035c00
 
831
                                        i18np("Do you really want to delete this item?",
 
832
                                                                "Do you really want to delete these %1 items?", numFiles),
 
833
                                        files,
 
834
                                        i18n("Delete Files"),
 
835
                                        KStandardGuiItem::del(), KStandardGuiItem::cancel(), QString(),
 
836
#else
653
837
                                        i18n("Do you really want to delete this item?",
654
838
                                                         "Do you really want to delete these %n items?", numFiles),
655
839
                                        files,
656
 
                                        i18n("Delete Files"), KStdGuiItem::del(), QString::null,
 
840
                                        i18n("Delete Files"),
 
841
                                        KStdGuiItem::del(), QString::null,
 
842
#endif
657
843
                                        KMessageBox::Dangerous) == KMessageBox::Continue)
658
844
#else
659
845
                QString txt = numFiles > 1 ?
672
858
                                QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
673
859
#endif
674
860
                {
 
861
#if QT_VERSION >= 0x040000
 
862
                        QList<QTreeWidgetItem*> itemsToDelete;
 
863
#endif
675
864
                        files.clear();
676
865
                        FileListItem* item = first();
677
866
                        while (item != 0) {
686
875
                                                // The file must be closed before deleting on Windows.
687
876
                                                item->setFile(0);
688
877
                                                if (QDir().remove(absFilename)) {
 
878
#if QT_VERSION >= 0x040000
 
879
                                                        itemsToDelete.append(item);
 
880
#else
689
881
                                                        delete item;
 
882
#endif
690
883
                                                } else {
691
 
                                                        item->setFile(createTaggedFile(dirInfo, filename));
 
884
                                                        item->setFile(TaggedFile::createFile(dirInfo, filename));
692
885
                                                        files.push_back(absFilename);
693
886
                                                }
694
887
                                        }
695
888
                                }
696
889
                                item = nextItem;
697
890
                        }
 
891
#if QT_VERSION >= 0x040000
 
892
                        qDeleteAll(itemsToDelete);
 
893
                        itemsToDelete.clear();
 
894
#endif
698
895
                        if (!files.empty()) {
699
896
#ifdef CONFIG_USE_KDE
700
897
                                KMessageBox::errorList(
701
 
                                        0, i18n("Error while deleting this item:",
702
 
                                                                        "Error while deleting these %n items:", files.size()),
 
898
                                        0,
 
899
#if KDE_VERSION >= 0x035c00
 
900
                                        i18np("Error while deleting this item:",
 
901
                                                                "Error while deleting these %1 items:", files.size()),
 
902
#else
 
903
                                        i18n("Error while deleting this item:",
 
904
                                                         "Error while deleting these %n items:", files.size()),
 
905
#endif
703
906
                                        files,
704
907
                                        i18n("File Error"));
705
908
#else
726
929
                                this,
727
930
                                i18n("Do you really want to delete this item?"),
728
931
                                QStringList(dirInfo->getDirname()),
729
 
                                i18n("Delete Files"), KStdGuiItem::del(), QString::null,
 
932
                                i18n("Delete Files"),
 
933
#if KDE_VERSION >= 0x035c00
 
934
                                KStandardGuiItem::del(), KStandardGuiItem::cancel(), QString(),
 
935
#else
 
936
                                KStdGuiItem::del(), QString::null,
 
937
#endif
730
938
                                KMessageBox::Dangerous) == KMessageBox::Continue
731
939
#else
732
940
#if QT_VERSION >= 0x030100
760
968
                }
761
969
        }
762
970
}
 
971
 
 
972
#if QT_VERSION >= 0x040000
 
973
/**
 
974
 * Expand an item.
 
975
 *
 
976
 * @param item item
 
977
 */
 
978
void FileList::expandItem(QTreeWidgetItem* item)
 
979
{
 
980
        FileListItem* fli = dynamic_cast<FileListItem*>(item);
 
981
        if (fli) {
 
982
                fli->setOpen(true);
 
983
        }
 
984
}
 
985
 
 
986
/**
 
987
 * Collapse an item.
 
988
 *
 
989
 * @param item item
 
990
 */
 
991
void FileList::collapseItem(QTreeWidgetItem* item)
 
992
{
 
993
        FileListItem* fli = dynamic_cast<FileListItem*>(item);
 
994
        if (fli) {
 
995
                fli->setOpen(false);
 
996
        }
 
997
}
 
998
 
 
999
/**
 
1000
 * Display a custom context menu with operations for selected files.
 
1001
 *
 
1002
 * @param pos  position where context menu is drawn on screen
 
1003
 */
 
1004
void FileList::customContextMenu(const QPoint& pos)
 
1005
{
 
1006
        contextMenu(currentItem(), mapToGlobal(pos));
 
1007
}
 
1008
 
 
1009
/**
 
1010
 * Expand or collapse an item which has no children.
 
1011
 *
 
1012
 * @param item item
 
1013
 */
 
1014
void FileList::expandOrCollapseEmptyItem(QTreeWidgetItem* item)
 
1015
{
 
1016
        FileListItem* fli = dynamic_cast<FileListItem*>(item);
 
1017
        if (fli && fli->getDirInfo() && !item->childCount()) {
 
1018
                fli->setOpen(!fli->isOpen());
 
1019
        }
 
1020
}
 
1021
#else
 
1022
void FileList::expandItem(QTreeWidgetItem*) {}
 
1023
void FileList::collapseItem(QTreeWidgetItem*) {}
 
1024
void FileList::customContextMenu(const QPoint&) {}
 
1025
void FileList::expandOrCollapseEmptyItem(QTreeWidgetItem*) {}
 
1026
#endif