summaryrefslogtreecommitdiffstats
path: root/ksquirrel/ksquirrel-libs-configurator/klc.ui.h
blob: 46b1bb3ff982d6994126523031055c3cf1a11af8 (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
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/

void KLC::init()
{
    changed = false;

    listEnabled->setSorting(0);
    listEnabled->header()->hide();

    listDisabled->setSorting(0);
    listDisabled->header()->hide();

    lister = new KDirLister;
    connect(lister, SIGNAL(completed(const KURL &)), this, SLOT(slotCompleted(const KURL &)));
    connect(lister, SIGNAL(deleteItem(KFileItem *)), this, SLOT(slotDeleteItem(KFileItem *)));
    connect(lister, SIGNAL(newItems(const KFileItemList &)), this, SLOT(slotNewItems(const KFileItemList &)));

    base = KURL::fromPathOrURL(SQ_KLIBS);

    backup = base;
    backup.addPath("backup");

    backupDir = backup.path();
    
    KIO::NetAccess::mkdir(backup, this);

    QTimer::singleShot(0, this, SLOT(slotLoad()));
}

void KLC::slotLoad()
{
    lister->openURL(base);
    lister->openURL(backup, true);
}

void KLC::destroy()
{
    delete lister;
}

void KLC::slotApply()
{
    changed = true;

    moveCodecs(true);
    moveCodecs(false);
}

void KLC::moveCodecs(bool e2d)
{
    KURL::List list;
    KURL codec;

    QListViewItemIterator it(e2d ? listEnabled : listDisabled);
    QCheckListItem *li;

    while((li = static_cast<QCheckListItem *>(it.current())))
    {
        if(li->isOn())
        {
	    codec = e2d ? base : backup;
    	    codec.addPath(li->text());
	    list.append(codec);
        }

	++it;
    }

    KIO::Job *job = KIO::move(list, e2d ? backup : base);

    connect(job, SIGNAL(result(KIO::Job *)), this, SLOT(slotDelResult(KIO::Job *)));
}

void KLC::slotCompleted(const KURL &u)
{
    if(u == base)
    {
	listEnabled->setEnabled(true);
	listEnabled->setCurrentItem(listEnabled->firstChild());
    }
    else
    {
	listDisabled->setEnabled(true);
	listDisabled->setCurrentItem(listDisabled->firstChild());
    }
}

void KLC::slotNewItems(const KFileItemList &list)
{
    KFileItemListIterator it(list);
    KFileItem *fi;
    QString soname = QString::fromLatin1(".so.%1").arg(SQ_KL_VER);

    while((fi = it.current()))
    {
	if(fi->isFile() && fi->name().endsWith(soname))
	    new  QCheckListItem(fi->url().directory().startsWith(backupDir) ? listDisabled:listEnabled, fi->name(), QCheckListItem::CheckBox);

	++it;
    }
}

void KLC::slotDeleteItem(KFileItem *fi)
{
    QListView *l = fi->url().directory().startsWith(backupDir) ? listDisabled:listEnabled;

    QListViewItemIterator it(l);
    QCheckListItem *li;
    QListViewItem *li2;

    while((li = static_cast<QCheckListItem *>(it.current())))
    {
        if(li->text() == fi->name())
        {
            li2 = li->itemBelow();

            if(!li2)
                li2 = li->itemAbove();

            delete li;

            l->setCurrentItem(li2);
            l->setSelected(li2, true);

            return;
        }

	++it;
    }
}

void KLC::slotDelResult(KIO::Job *job)
{
    if(job && job->error())
	job->showErrorDialog(this);
}

void KLC::closeEvent(QCloseEvent *ev)
{
    QString data;

    if(changed)
	kapp->dcopClient()->send("ksquirrel", "ksquirrel", "reload_codecs()", data);

    ev->accept();
}