Diffstat (limited to 'noncore/net/opieirc/ircserverlist.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircserverlist.cpp | 90 |
1 files changed, 83 insertions, 7 deletions
diff --git a/noncore/net/opieirc/ircserverlist.cpp b/noncore/net/opieirc/ircserverlist.cpp index 964fa13..b2d746a 100644 --- a/noncore/net/opieirc/ircserverlist.cpp +++ b/noncore/net/opieirc/ircserverlist.cpp | |||
@@ -1,2 +1,3 @@ | |||
1 | #include <stdio.h> | ||
1 | #include <qlayout.h> | 2 | #include <qlayout.h> |
2 | #include <qlabel.h> | 3 | #include <qlabel.h> |
@@ -5,9 +6,22 @@ | |||
5 | #include "ircserverlist.h" | 6 | #include "ircserverlist.h" |
6 | #include "ircservereditor.h" | 7 | #include "ircservereditor.h" |
8 | #include <stdio.h> | ||
7 | 9 | ||
8 | class IRCListBoxServer : public QListBoxText { | 10 | class IRCListBoxServer : public QListBoxText { |
9 | public: | 11 | public: |
10 | IRCListBoxServer(IRCServer server); | 12 | IRCListBoxServer(IRCServer server) : QListBoxText(server.name()) { |
11 | QString text(); | 13 | m_server = server; |
14 | } | ||
15 | |||
16 | IRCServer server() { | ||
17 | return m_server; | ||
18 | } | ||
19 | |||
20 | void setServer(IRCServer server) { | ||
21 | m_server = server; | ||
22 | setText(m_server.name()); | ||
23 | } | ||
24 | protected: | ||
25 | IRCServer m_server; | ||
12 | }; | 26 | }; |
13 | 27 | ||
@@ -15,7 +29,6 @@ IRCServerList::IRCServerList(QWidget* parent, const char *name, bool modal, WFla | |||
15 | QVBoxLayout *layout = new QVBoxLayout(this, 5, 5); | 29 | QVBoxLayout *layout = new QVBoxLayout(this, 5, 5); |
16 | setCaption(tr("Serverlist Browser")); | 30 | setCaption(tr("Serverlist Browser")); |
17 | m_config = new Config("OpieIRC"); | ||
18 | m_config->setGroup("OpieIRC"); | ||
19 | QLabel *label = new QLabel(tr("Please choose a server profile"), this); | 31 | QLabel *label = new QLabel(tr("Please choose a server profile"), this); |
32 | label->setAlignment(AlignHCenter); | ||
20 | layout->addWidget(label); | 33 | layout->addWidget(label); |
21 | m_list = new QListBox(this); | 34 | m_list = new QListBox(this); |
@@ -29,4 +42,27 @@ IRCServerList::IRCServerList(QWidget* parent, const char *name, bool modal, WFla | |||
29 | connect(add, SIGNAL(clicked()), this, SLOT(addServer())); | 42 | connect(add, SIGNAL(clicked()), this, SLOT(addServer())); |
30 | layout->addWidget(buttons); | 43 | layout->addWidget(buttons); |
44 | /* Load the configuration file */ | ||
45 | m_config = new Config("OpieIRC"); | ||
46 | m_config->setGroup("OpieIRC"); | ||
47 | int count = m_config->readNumEntry("ServerCount", 0); | ||
48 | if (count) { | ||
49 | for (int i=0; i<count; i++) { | ||
50 | m_config->setGroup("OpieIRC"); | ||
51 | QString name = m_config->readEntry("Server"+QString::number(i)); | ||
52 | if (name.length() > 0) { | ||
53 | IRCServer server; | ||
54 | m_config->setGroup(name); | ||
55 | server.setName(name); | ||
56 | server.setHostname(m_config->readEntry("Hostname")); | ||
57 | server.setPort(m_config->readNumEntry("Port")); | ||
58 | server.setUsername(m_config->readEntry("Username")); | ||
59 | server.setPassword(m_config->readEntry("Password")); | ||
60 | server.setNick(m_config->readEntry("Nick")); | ||
61 | server.setRealname(m_config->readEntry("Realname")); | ||
62 | m_list->insertItem(new IRCListBoxServer(server)); | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | |||
31 | showMaximized(); | 67 | showMaximized(); |
32 | } | 68 | } |
@@ -37,16 +73,56 @@ void IRCServerList::addServer() { | |||
37 | if (editor.exec() == QDialog::Accepted) { | 73 | if (editor.exec() == QDialog::Accepted) { |
38 | server = editor.getServer(); | 74 | server = editor.getServer(); |
39 | //m_servers->append(server); | 75 | /* Gets deleted by QListBox, so this is ok */ |
40 | update(); | 76 | m_list->insertItem(new IRCListBoxServer(server)); |
41 | } | 77 | } |
42 | } | 78 | } |
43 | 79 | ||
44 | void IRCServerList::delServer() { | 80 | void IRCServerList::delServer() { |
81 | int index = m_list->currentItem(); | ||
82 | if (index != -1) { | ||
83 | m_list->removeItem(index); | ||
84 | } | ||
45 | } | 85 | } |
46 | 86 | ||
47 | void IRCServerList::editServer() { | 87 | void IRCServerList::editServer() { |
88 | int index = m_list->currentItem(); | ||
89 | if (index != -1) { | ||
90 | IRCListBoxServer *item = (IRCListBoxServer *)m_list->item(index); | ||
91 | IRCServer server = item->server(); | ||
92 | IRCServerEditor editor(server, this, "ServerEditor", TRUE); | ||
93 | if (editor.exec() == QDialog::Accepted) { | ||
94 | server = editor.getServer(); | ||
95 | item->setServer(server); | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | |||
100 | int IRCServerList::exec() { | ||
101 | int returncode = QDialog::exec(); | ||
102 | /* Now save the changes */ | ||
103 | m_config->setGroup("OpieIRC"); | ||
104 | m_config->clearGroup(); | ||
105 | m_config->writeEntry("ServerCount", QString::number(m_list->count())); | ||
106 | for (unsigned int i=0; i<m_list->count(); i++) { | ||
107 | IRCServer server = ((IRCListBoxServer *)m_list->item(i))->server(); | ||
108 | m_config->setGroup("OpieIRC"); | ||
109 | m_config->writeEntry("Server"+QString::number(i), server.name()); | ||
110 | m_config->setGroup(server.name()); | ||
111 | m_config->writeEntry("Hostname", server.hostname()); | ||
112 | m_config->writeEntry("Port", QString::number(server.port())); | ||
113 | m_config->writeEntry("Username", server.username()); | ||
114 | m_config->writeEntry("Password", server.password()); | ||
115 | m_config->writeEntry("Nick", server.nick()); | ||
116 | m_config->writeEntry("Realname", server.realname()); | ||
117 | } | ||
118 | return returncode; | ||
119 | } | ||
120 | |||
121 | bool IRCServerList::hasServer() { | ||
122 | return (m_list->currentItem() != -1); | ||
48 | } | 123 | } |
49 | 124 | ||
50 | void IRCServerList::update() { | 125 | IRCServer IRCServerList::server() { |
126 | return ((IRCListBoxServer *)m_list->item(m_list->currentItem()))->server(); | ||
51 | } | 127 | } |
52 | 128 | ||