summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc/ircserverlist.cpp
authorwazlaf <wazlaf>2002-09-11 22:22:04 (UTC)
committer wazlaf <wazlaf>2002-09-11 22:22:04 (UTC)
commit4864665ad76095620fdf5aa19d24f05967f32b40 (patch) (side-by-side diff)
tree4b3e371b5da03292ce09f7e388885dd3ec049ff8 /noncore/net/opieirc/ircserverlist.cpp
parent7ab82ad13aaf708ffba4bf4294d29b789007ddde (diff)
downloadopie-4864665ad76095620fdf5aa19d24f05967f32b40.zip
opie-4864665ad76095620fdf5aa19d24f05967f32b40.tar.gz
opie-4864665ad76095620fdf5aa19d24f05967f32b40.tar.bz2
serverlist browser
Diffstat (limited to 'noncore/net/opieirc/ircserverlist.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircserverlist.cpp90
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,22 +1,35 @@
+#include <stdio.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qhbox.h>
#include <qpushbutton.h>
#include "ircserverlist.h"
#include "ircservereditor.h"
+#include <stdio.h>
class IRCListBoxServer : public QListBoxText {
public:
- IRCListBoxServer(IRCServer server);
- QString text();
+ IRCListBoxServer(IRCServer server) : QListBoxText(server.name()) {
+ m_server = server;
+ }
+
+ IRCServer server() {
+ return m_server;
+ }
+
+ void setServer(IRCServer server) {
+ m_server = server;
+ setText(m_server.name());
+ }
+protected:
+ IRCServer m_server;
};
IRCServerList::IRCServerList(QWidget* parent, const char *name, bool modal, WFlags f) : QDialog(parent, name, modal, f) {
QVBoxLayout *layout = new QVBoxLayout(this, 5, 5);
setCaption(tr("Serverlist Browser"));
- m_config = new Config("OpieIRC");
- m_config->setGroup("OpieIRC");
QLabel *label = new QLabel(tr("Please choose a server profile"), this);
+ label->setAlignment(AlignHCenter);
layout->addWidget(label);
m_list = new QListBox(this);
layout->addWidget(m_list);
@@ -28,6 +41,29 @@ IRCServerList::IRCServerList(QWidget* parent, const char *name, bool modal, WFla
connect(edit, SIGNAL(clicked()), this, SLOT(editServer()));
connect(add, SIGNAL(clicked()), this, SLOT(addServer()));
layout->addWidget(buttons);
+ /* Load the configuration file */
+ m_config = new Config("OpieIRC");
+ m_config->setGroup("OpieIRC");
+ int count = m_config->readNumEntry("ServerCount", 0);
+ if (count) {
+ for (int i=0; i<count; i++) {
+ m_config->setGroup("OpieIRC");
+ QString name = m_config->readEntry("Server"+QString::number(i));
+ if (name.length() > 0) {
+ IRCServer server;
+ m_config->setGroup(name);
+ server.setName(name);
+ server.setHostname(m_config->readEntry("Hostname"));
+ server.setPort(m_config->readNumEntry("Port"));
+ server.setUsername(m_config->readEntry("Username"));
+ server.setPassword(m_config->readEntry("Password"));
+ server.setNick(m_config->readEntry("Nick"));
+ server.setRealname(m_config->readEntry("Realname"));
+ m_list->insertItem(new IRCListBoxServer(server));
+ }
+ }
+ }
+
showMaximized();
}
@@ -36,18 +72,58 @@ void IRCServerList::addServer() {
IRCServerEditor editor(server, this, "ServerEditor", TRUE);
if (editor.exec() == QDialog::Accepted) {
server = editor.getServer();
- //m_servers->append(server);
- update();
+ /* Gets deleted by QListBox, so this is ok */
+ m_list->insertItem(new IRCListBoxServer(server));
}
}
void IRCServerList::delServer() {
+ int index = m_list->currentItem();
+ if (index != -1) {
+ m_list->removeItem(index);
+ }
}
void IRCServerList::editServer() {
+ int index = m_list->currentItem();
+ if (index != -1) {
+ IRCListBoxServer *item = (IRCListBoxServer *)m_list->item(index);
+ IRCServer server = item->server();
+ IRCServerEditor editor(server, this, "ServerEditor", TRUE);
+ if (editor.exec() == QDialog::Accepted) {
+ server = editor.getServer();
+ item->setServer(server);
+ }
+ }
+}
+
+int IRCServerList::exec() {
+ int returncode = QDialog::exec();
+ /* Now save the changes */
+ m_config->setGroup("OpieIRC");
+ m_config->clearGroup();
+ m_config->writeEntry("ServerCount", QString::number(m_list->count()));
+ for (unsigned int i=0; i<m_list->count(); i++) {
+ IRCServer server = ((IRCListBoxServer *)m_list->item(i))->server();
+ m_config->setGroup("OpieIRC");
+ m_config->writeEntry("Server"+QString::number(i), server.name());
+ m_config->setGroup(server.name());
+ m_config->writeEntry("Hostname", server.hostname());
+ m_config->writeEntry("Port", QString::number(server.port()));
+ m_config->writeEntry("Username", server.username());
+ m_config->writeEntry("Password", server.password());
+ m_config->writeEntry("Nick", server.nick());
+ m_config->writeEntry("Realname", server.realname());
+ }
+ return returncode;
+}
+
+bool IRCServerList::hasServer() {
+ return (m_list->currentItem() != -1);
}
-void IRCServerList::update() {
+IRCServer IRCServerList::server() {
+ return ((IRCListBoxServer *)m_list->item(m_list->currentItem()))->server();
}
IRCServerList::~IRCServerList() {