summaryrefslogtreecommitdiffstats
path: root/juk/tagguesserconfigdlg.cpp
blob: f3af1f43d897d621d09dc48528d51d2d8e0b53f6 (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
/*
 * tagguesserconfigdlg.cpp - (c) 2003 Frerich Raabe <raabe@kde.org>
 *
 * 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 "tagguesser.h"
#include "tagguesserconfigdlg.h"
#include "tagguesserconfigdlgwidget.h"

#include <kiconloader.h>
#include <klistview.h>
#include <klocale.h>
#include <kpushbutton.h>
#include <klineedit.h>
#include <kapplication.h>

#include <qtoolbutton.h>
#include <qevent.h>

TagGuesserConfigDlg::TagGuesserConfigDlg(QWidget *parent, const char *name)
    : KDialogBase(parent, name, true, i18n("Tag Guesser Configuration"),
                  Ok | Cancel, Ok, true)
{
    m_child = new TagGuesserConfigDlgWidget(this, "child");
    setMainWidget(m_child);

    m_child->lvSchemes->setItemsRenameable(true);
    m_child->lvSchemes->setSorting(-1);
    m_child->lvSchemes->setDefaultRenameAction(QListView::Accept);
    m_child->bMoveUp->setIconSet(BarIconSet("1uparrow"));
    m_child->bMoveDown->setIconSet(BarIconSet("1downarrow"));

    const QStringList schemes = TagGuesser::schemeStrings();
    QStringList::ConstIterator it = schemes.begin();
    QStringList::ConstIterator end = schemes.end();
    for (; it != end; ++it) {
        KListViewItem *item = new KListViewItem(m_child->lvSchemes, *it);
        item->moveItem(m_child->lvSchemes->lastItem());
    }

    connect(m_child->lvSchemes, SIGNAL(currentChanged(QListViewItem *)),
            this, SLOT(slotCurrentChanged(QListViewItem *)));
    connect(m_child->lvSchemes, SIGNAL(doubleClicked(QListViewItem *, const QPoint &, int)),
            this, SLOT(slotRenameItem(QListViewItem *, const QPoint &, int)));
    connect(m_child->bMoveUp, SIGNAL(clicked()), this, SLOT(slotMoveUpClicked()));
    connect(m_child->bMoveDown, SIGNAL(clicked()), this, SLOT(slotMoveDownClicked()));
    connect(m_child->bAdd, SIGNAL(clicked()), this, SLOT(slotAddClicked()));
    connect(m_child->bModify, SIGNAL(clicked()), this, SLOT(slotModifyClicked()));
    connect(m_child->bRemove, SIGNAL(clicked()), this, SLOT(slotRemoveClicked()));

    m_child->lvSchemes->setSelected(m_child->lvSchemes->firstChild(), true);
    slotCurrentChanged(m_child->lvSchemes->currentItem());

    resize( 400, 300 );
}

void TagGuesserConfigDlg::accept()
{
    if(m_child->lvSchemes->renameLineEdit()) {
        QKeyEvent returnKeyPress(QEvent::KeyPress, Key_Return, 0, 0);
        KApplication::sendEvent(m_child->lvSchemes->renameLineEdit(), &returnKeyPress);
    }

    QStringList schemes;
    for (QListViewItem *it = m_child->lvSchemes->firstChild(); it; it = it->nextSibling())
        schemes += it->text(0);
    TagGuesser::setSchemeStrings(schemes);
    KDialogBase::accept();
}

void TagGuesserConfigDlg::slotCurrentChanged(QListViewItem *item)
{
    m_child->bMoveUp->setEnabled(item != 0 && item->itemAbove() != 0);
    m_child->bMoveDown->setEnabled(item != 0 && item->itemBelow() != 0);
    m_child->bModify->setEnabled(item != 0);
    m_child->bRemove->setEnabled(item != 0);
}

void TagGuesserConfigDlg::slotRenameItem(QListViewItem *item, const QPoint &, int c)
{
    m_child->lvSchemes->rename(item, c);
}

void TagGuesserConfigDlg::slotMoveUpClicked()
{
    QListViewItem *item = m_child->lvSchemes->currentItem();
    if(item->itemAbove() == m_child->lvSchemes->firstChild())
        item->itemAbove()->moveItem(item);
    else
      item->moveItem(item->itemAbove()->itemAbove());
    m_child->lvSchemes->ensureItemVisible(item);
    slotCurrentChanged(item);
}

void TagGuesserConfigDlg::slotMoveDownClicked()
{
    QListViewItem *item = m_child->lvSchemes->currentItem();
    item->moveItem(item->itemBelow());
    m_child->lvSchemes->ensureItemVisible(item);
    slotCurrentChanged(item);
}

void TagGuesserConfigDlg::slotAddClicked()
{
    KListViewItem *item = new KListViewItem(m_child->lvSchemes);
    m_child->lvSchemes->rename(item, 0);
}

void TagGuesserConfigDlg::slotModifyClicked()
{
    m_child->lvSchemes->rename(m_child->lvSchemes->currentItem(), 0);
}

void TagGuesserConfigDlg::slotRemoveClicked()
{
    delete m_child->lvSchemes->currentItem();
}

#include "tagguesserconfigdlg.moc"