summaryrefslogtreecommitdiffstats
path: root/ksirc/KSPrefs/page_servchan.cpp
blob: fc9e73e6d6f37fd74487a88664ec4597d45beffc (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
/***************************************************************************
 *                                                                         *
 *   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 "page_servchan.h"

#include <tqlistbox.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tdeapplication.h>
#include <tdeconfig.h>

PageServChan::PageServChan( TQWidget *parent, const char *name ) : PageServChanBase( parent, name)
{
    connect(serverDeleteItemPB, TQ_SIGNAL(pressed()), this, TQ_SLOT(deletePressedSL()));
    connect(ServerAddItemPB, TQ_SIGNAL(pressed()), this, TQ_SLOT(addPressedSL()));
    connect(chanDeleteItmPB, TQ_SIGNAL(pressed()), this, TQ_SLOT(deletePressedCL()));
    connect(ChanAddItemPB, TQ_SIGNAL(pressed()), this, TQ_SLOT(addPressedCL()));

}

PageServChan::~PageServChan()
{
}

void PageServChan::saveConfig()
{
    TQStringList sLB;
    uint i;
    for(i = 0; i < serverLB->count(); i++){
        TQString txt = serverLB->text(i);
        if(!txt.isNull())
            sLB << txt;
    }
    TDEConfig *conf = kapp->config();
    conf->setGroup("ServerList");
    conf->writeEntry("RecentServers", sLB);

    TQStringList sCL;
    for(i = 0; i < channelLB->count(); i++){
        TQString txt = channelLB->text(i);
        if(!txt.isNull())
            sCL << txt;
    }
    conf->setGroup("Recent");
    conf->writeEntry("Channels", sCL);
}

void PageServChan::readConfig( const KSOServChan * )
{
    TDEConfig *conf = kapp->config();
    conf->setGroup("ServerList");
    TQStringList recent = conf->readListEntry("RecentServers");
    recent.sort();
    serverLB->insertStringList(recent);
    conf->setGroup("Recent");
    recent = conf->readListEntry("Channels");
    recent.sort();
    channelLB->insertStringList(recent);
}

void PageServChan::defaultConfig()
{
    readConfig();
}

void PageServChan::deletePressedSL() {
    int item = serverLB->currentItem();
    if(item >= 0){
        serverLB->removeItem(item);
    }
    emit modified();
}

void PageServChan::addPressedSL() {
    uint i;
    TQString txt = LineEdit6->text();

    for(i = 0; i < serverLB->count(); i++){
        if(txt == serverLB->text(i)){
            tqWarning("Server already in the list!");
            return;
        }
    }

    serverLB->insertItem(txt);
    serverLB->sort();
    LineEdit6->clear();
    emit modified();
    for(i = 0; i < serverLB->count(); i++){
        if(txt == serverLB->text(i)){
            serverLB->setCurrentItem(i);
            serverLB->ensureCurrentVisible();
            return;
        }
    }
}

void PageServChan::deletePressedCL() {
    int item = channelLB->currentItem();
    if(item >= 0){
        channelLB->removeItem(item);
    }
    emit modified();
}

void PageServChan::addPressedCL() {
    uint i;
    TQString txt = LineEdit6_2->text();

    for(i = 0; i < channelLB->count(); i++){
        if(txt == channelLB->text(i)){
            tqWarning("Server already in the list!");
            return;
        }
    }

    channelLB->insertItem(txt);
    channelLB->sort();
    LineEdit6_2->clear();
    emit modified();
    for(i = 0; i < channelLB->count(); i++){
        if(txt == channelLB->text(i)){
            channelLB->setCurrentItem(i);
            channelLB->ensureCurrentVisible();
            return;
        }
    }
}
#include "page_servchan.moc"