From 4864665ad76095620fdf5aa19d24f05967f32b40 Mon Sep 17 00:00:00 2001 From: wazlaf Date: Wed, 11 Sep 2002 22:22:04 +0000 Subject: serverlist browser --- (limited to 'noncore/net/opieirc') diff --git a/noncore/net/opieirc/.cvsignore b/noncore/net/opieirc/.cvsignore new file mode 100644 index 0000000..39391f4 --- a/dev/null +++ b/noncore/net/opieirc/.cvsignore @@ -0,0 +1,3 @@ +Makefile +Makefile.in +moc_*.cpp diff --git a/noncore/net/opieirc/ircquerytab.cpp b/noncore/net/opieirc/ircquerytab.cpp new file mode 100644 index 0000000..6d24845 --- a/dev/null +++ b/noncore/net/opieirc/ircquerytab.cpp @@ -0,0 +1,2 @@ +#include "ircquerytab.h" + diff --git a/noncore/net/opieirc/ircquerytab.h b/noncore/net/opieirc/ircquerytab.h new file mode 100644 index 0000000..fac976d --- a/dev/null +++ b/noncore/net/opieirc/ircquerytab.h @@ -0,0 +1,24 @@ +/* + OpieIRC - An embedded IRC client + Copyright (C) 2002 Wenzel Jakob + + 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef __IRCQUERYTAB_H +#define __IRCQUERYTAB_H + +#endif /* __IRCQUERYTAB_H */ diff --git a/noncore/net/opieirc/ircserver.cpp b/noncore/net/opieirc/ircserver.cpp index 33a788b..e16e2b2 100644 --- a/noncore/net/opieirc/ircserver.cpp +++ b/noncore/net/opieirc/ircserver.cpp @@ -1,15 +1,15 @@ #include "ircserver.h" IRCServer::IRCServer() { - m_port = 0; + m_port = 6667; } void IRCServer::setHostname(QString hostname) { m_hostname = hostname; } -void IRCServer::setDescription(QString description) { - m_description = description; +void IRCServer::setName(QString name) { + m_name = name; } void IRCServer::setPort(int port) { @@ -36,8 +36,8 @@ QString IRCServer::hostname() { return m_hostname; } -QString IRCServer::description() { - return m_description; +QString IRCServer::name() { + return m_name; } unsigned short int IRCServer::port() { diff --git a/noncore/net/opieirc/ircserver.h b/noncore/net/opieirc/ircserver.h index 5f06c73..f56f231 100644 --- a/noncore/net/opieirc/ircserver.h +++ b/noncore/net/opieirc/ircserver.h @@ -30,8 +30,8 @@ class IRCServer { public: IRCServer(); + void setName(QString name); void setHostname(QString hostname); - void setDescription(QString description); void setPort(int port); void setUsername(QString username); void setPassword(QString password); @@ -39,7 +39,7 @@ public: void setRealname(QString realname); QString hostname(); - QString description(); + QString name(); unsigned short int port(); QString username(); QString password(); @@ -47,7 +47,7 @@ public: QString realname(); protected: QString m_hostname; - QString m_description; + QString m_name; unsigned short int m_port; QString m_username; QString m_password; diff --git a/noncore/net/opieirc/ircservereditor.cpp b/noncore/net/opieirc/ircservereditor.cpp index 1b157d6..798081f 100644 --- a/noncore/net/opieirc/ircservereditor.cpp +++ b/noncore/net/opieirc/ircservereditor.cpp @@ -1,33 +1,30 @@ +#include #include #include #include "ircservereditor.h" IRCServerEditor::IRCServerEditor(IRCServer server, QWidget* parent, const char* name, bool modal = FALSE, WFlags f) : QDialog(parent, name, modal, f) { QGridLayout *layout = new QGridLayout(this, 6, 2, 5, 5); - QLabel *label = new QLabel(tr("Hostname :"), this); - m_hostname = new QLineEdit(server.hostname(), this); + QLabel *label = new QLabel(tr("Profile name :"), this); + m_name = new QLineEdit(server.name(), this); layout->addWidget(label, 0, 0); - layout->addWidget(m_hostname, 0, 1); + layout->addWidget(m_name, 0, 1); + label = new QLabel(tr("Hostname :"), this); + m_hostname = new QLineEdit(server.hostname(), this); + layout->addWidget(label, 1, 0); + layout->addWidget(m_hostname, 1, 1); label = new QLabel(tr("Port :"), this); m_port = new QLineEdit(QString::number(server.port()), this); - layout->addWidget(label, 1, 0); - layout->addWidget(m_port, 1, 1); + layout->addWidget(label, 2, 0); + layout->addWidget(m_port, 2, 1); label = new QLabel(tr("Nickname :"), this); m_nickname = new QLineEdit(server.nick(), this); - layout->addWidget(label, 2, 0); - layout->addWidget(m_nickname, 2, 1); - label = new QLabel(tr("Description :"), this); - m_description = new QLineEdit(server.description(), this); layout->addWidget(label, 3, 0); - layout->addWidget(m_description, 3, 1); + layout->addWidget(m_nickname, 3, 1); label = new QLabel(tr("Realname :"), this); m_realname = new QLineEdit(server.realname(), this); layout->addWidget(label, 4, 0); layout->addWidget(m_realname, 4, 1); - label = new QLabel(tr("Username :"), this); - m_username = new QLineEdit(server.username(), this); - layout->addWidget(label, 3, 0); - layout->addWidget(m_username, 3, 1); label = new QLabel(tr("Password :"), this); m_password = new QLineEdit(server.password(), this); layout->addWidget(label, 5, 0); @@ -36,14 +33,29 @@ IRCServerEditor::IRCServerEditor(IRCServer server, QWidget* parent, const char* } +void IRCServerEditor::accept() { + if (m_name->text().length()==0) + QMessageBox::critical(this, tr("Error"), tr("Profile name required")); + else if (m_hostname->text().length()==0) + QMessageBox::critical(this, tr("Error"), tr("Host name required")); + else if (m_port->text().toInt()<=0) + QMessageBox::critical(this, tr("Error"), tr("Port required")); + else if (m_nickname->text().length()==0) + QMessageBox::critical(this, tr("Error"), tr("Nickname required")); + else if (m_realname->text().length()==0) + QMessageBox::critical(this, tr("Error"), tr("Realname required")); + else + QDialog::accept(); +} + IRCServer IRCServerEditor::getServer() { IRCServer server; + server.setName(m_name->text()); server.setHostname(m_hostname->text()); server.setPort(m_port->text().toInt()); server.setNick(m_nickname->text()); - server.setDescription(m_description->text()); server.setRealname(m_realname->text()); - server.setUsername(m_username->text()); + server.setUsername(m_nickname->text()); server.setPassword(m_password->text()); return server; } diff --git a/noncore/net/opieirc/ircservereditor.h b/noncore/net/opieirc/ircservereditor.h index 86cdf32..20c94f7 100644 --- a/noncore/net/opieirc/ircservereditor.h +++ b/noncore/net/opieirc/ircservereditor.h @@ -30,12 +30,13 @@ class IRCServerEditor : public QDialog { public: IRCServerEditor(IRCServer server, QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0); IRCServer getServer(); +protected slots: + void accept(); protected: + QLineEdit *m_name; QLineEdit *m_hostname; QLineEdit *m_port; - QLineEdit *m_description; QLineEdit *m_nickname; - QLineEdit *m_username; QLineEdit *m_password; QLineEdit *m_realname; }; 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 #include #include #include #include #include "ircserverlist.h" #include "ircservereditor.h" +#include 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; isetGroup("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; icount(); 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() { diff --git a/noncore/net/opieirc/ircserverlist.h b/noncore/net/opieirc/ircserverlist.h index ad9231d..d61210e 100644 --- a/noncore/net/opieirc/ircserverlist.h +++ b/noncore/net/opieirc/ircserverlist.h @@ -31,16 +31,20 @@ class IRCServerList : public QDialog { Q_OBJECT public: IRCServerList(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0); + int exec(); + /* Check whether a server was selected */ + bool hasServer(); + /* Return the selected server */ + IRCServer server(); + ~IRCServerList(); public slots: void addServer(); void delServer(); void editServer(); protected: - void update(); -protected: - Config *m_config; - QListBox *m_list; + Config *m_config; + QListBox *m_list; }; #endif /* __IRCSERVERLIST_H */ diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index 1f377aa..724f4bd 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp @@ -1,12 +1,12 @@ #include #include "ircservertab.h" -IRCServerTab::IRCServerTab(IRCServer *server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { +IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { m_server = server; - m_session = new IRCSession(m_server); + m_session = new IRCSession(&m_server); m_mainWindow = mainWindow; m_close = FALSE; - m_description->setText(tr("Connection to")+" " + server->hostname() + ":" + QString::number(server->port()) + ""); + m_description->setText(tr("Connection to")+" " + server.hostname() + ":" + QString::number(server.port()) + ""); m_textview = new QTextView(this); m_textview->setHScrollBarMode(QScrollView::AlwaysOff); m_textview->setVScrollBarMode(QScrollView::AlwaysOn); @@ -30,7 +30,6 @@ IRCServerTab::~IRCServerTab() { m_mainWindow->killTab(it.current()); } delete m_session; - delete m_server; } void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { @@ -46,7 +45,7 @@ IRCSession *IRCServerTab::session() { } IRCServer *IRCServerTab::server() { - return m_server; + return &m_server; } void IRCServerTab::processCommand() { diff --git a/noncore/net/opieirc/ircservertab.h b/noncore/net/opieirc/ircservertab.h index 79b5876..fa9a0a3 100644 --- a/noncore/net/opieirc/ircservertab.h +++ b/noncore/net/opieirc/ircservertab.h @@ -30,7 +30,7 @@ class IRCServerTab : public IRCTab { Q_OBJECT public: /* IRCTab implementation */ - IRCServerTab(IRCServer *server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); + IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); ~IRCServerTab(); QString title(); IRCSession *session(); @@ -49,7 +49,7 @@ protected slots: void display(IRCOutput output); protected: bool m_close; - IRCServer *m_server; + IRCServer m_server; IRCSession *m_session; MainWindow *m_mainWindow; QTextView *m_textview; diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp index bc0b0d1..3d13ee9 100644 --- a/noncore/net/opieirc/mainwindow.cpp +++ b/noncore/net/opieirc/mainwindow.cpp @@ -59,21 +59,10 @@ void MainWindow::killTab(IRCTab *tab) { } void MainWindow::newConnection() { - IRCServer *server = new IRCServer(); - server->setHostname("irc.openprojects.net"); - server->setPort(6667); - server->setDescription("OpenProjects"); - server->setNick("opie-irc"); - server->setUsername("opie-irc"); - server->setRealname("opie-irc"); - IRCServerTab *serverTab = new IRCServerTab(server, this, m_tabWidget); - addTab(serverTab); - serverTab->doConnect(); - - /* - * Serverlist : not functional yet - IRCServerList *list = new IRCServerList(this, "ServerList", TRUE); - list->exec(); - delete list; - */ + IRCServerList list(this, "ServerList", TRUE); + if (list.exec() == QDialog::Accepted && list.hasServer()) { + IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget); + addTab(serverTab); + serverTab->doConnect(); + } } diff --git a/noncore/net/opieirc/opieirc.pro b/noncore/net/opieirc/opieirc.pro index d24535b..0e188e4 100644 --- a/noncore/net/opieirc/opieirc.pro +++ b/noncore/net/opieirc/opieirc.pro @@ -7,7 +7,8 @@ HEADERS = ircchannel.h ircconnection.h \ ircperson.h ircserver.h ircsession.h \ mainwindow.h irctab.h ircservertab.h \ ircchanneltab.h ircchannellist.h \ - ircserverlist.h ircservereditor.h + ircserverlist.h ircservereditor.h \ + ircquerytab.h SOURCES = ircchannel.cpp ircconnection.cpp \ ircmessage.cpp \ ircmessageparser.cpp ircoutput.cpp \ @@ -15,7 +16,8 @@ SOURCES = ircchannel.cpp ircconnection.cpp \ ircsession.cpp main.cpp mainwindow.cpp \ irctab.cpp ircservertab.cpp \ ircchanneltab.cpp ircchannellist.cpp \ - ircserverlist.cpp ircservereditor.cpp + ircserverlist.cpp ircservereditor.cpp \ + ircquerytab.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -- cgit v0.9.0.2