summaryrefslogtreecommitdiffstats
path: root/ksirc/KSPrefs/page_startup.cpp
blob: 37b3f8756e50cce37cb663c02dda1b8ef543e132 (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
/***************************************************************************
 *                                                                         *
 *   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 <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqlistbox.h>

#include <kapplication.h>
#include <kconfig.h>
#include <keditlistbox.h>

#include <kdebug.h>

#include "page_startup.h"

PageStartup::PageStartup( TQWidget *tqparent, const char *name ) : PageStartupBase( tqparent, name)
{
    notifyLB->upButton()->hide();
    notifyLB->downButton()->hide();
    serverLB->upButton()->hide();
    serverLB->downButton()->hide();

    TQListBox *lb = serverLB->listBox();
    connect(lb, TQT_SIGNAL(highlighted(int)),
	    this, TQT_SLOT(clickedLB(int)));

    changing = false;

}

PageStartup::~PageStartup()
{
}

void PageStartup::saveConfig()
{
    KSOServer glb = ksopts->server["global"];
    TQStringList items = serverLB->items();

    ksopts->server.clear();

    TQStringList::iterator it = items.begin();
    for( ; it != items.end(); ++it){
        ksopts->server[*it] = server[*it];
    }
    if(!ksopts->server.tqcontains("global")){
        ksopts->server["global"] = glb;
    }

}

void PageStartup::readConfig( const KSOptions *opts )
{
    server = opts->server;

    changing = true;
    ServerOpMap::Iterator it;
    for ( it = server.begin(); it != server.end(); ++it ) {
        if(it.data().globalCopy == false)
	    serverLB->insertItem(it.key());
    }
    TQListBoxItem *item = serverLB->listBox()->tqfindItem("global");
    serverLB->listBox()->setSelected(item, true);
    changing = false;
    clickedLB(serverLB->listBox()->index(item));

}

void PageStartup::defaultConfig()
{
    KSOptions opts;
    readConfig( &opts );
}

void PageStartup::changed()
{
    emit modified();

    TQString ser = serverLB->currentText();
    if(ser.isEmpty())
	return;

    if(changing)
        return;

    kdDebug(5008) << "got changed for: " << ser <<endl;

    server[ser].nick = nickLE->text();
    server[ser].altNick = altNickLE->text();
    server[ser].realName = rnLE->text();
    server[ser].userID = uiLE->text();

    server[ser].notifyList.clear();
    for ( int i = 0; i < notifyLB->count(); ++i)
	server[ser].notifyList.append( notifyLB->text( i ) );
    server[ser].globalCopy = false;

}

void PageStartup::clickedLB(int index)
{

    TQString text = serverLB->text(index);
    if(!server.tqcontains(text)){
	server[text] = server["global"];
        server[text].globalCopy = true;
    }

    changing = true;
    notifyLB->clear();

    nickLE->setText( server[text].nick );
    altNickLE->setText( server[text].altNick );
    rnLE->setText( server[text].realName );
    uiLE->setText( server[text].userID );
    notifyLB->insertStringList( server[text].notifyList );
    changing = false;
}

#include "page_startup.moc"