summaryrefslogtreecommitdiffstats
path: root/src/modules/mircimport
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 02:13:59 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 02:13:59 +0000
commita6d58bb6052ac8cb01805a48c4ad2f129126116f (patch)
treedd867a099fcbb263a8009a9fb22695b87855dad6 /src/modules/mircimport
downloadkvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.tar.gz
kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.zip
Added KDE3 version of kvirc
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/modules/mircimport')
-rw-r--r--src/modules/mircimport/Makefile.am22
-rw-r--r--src/modules/mircimport/caps/Makefile.am9
-rw-r--r--src/modules/mircimport/caps/mircimport1
-rw-r--r--src/modules/mircimport/libkvimircimport.cpp385
-rw-r--r--src/modules/mircimport/libkvimircimport.h82
-rw-r--r--src/modules/mircimport/pics/Makefile.am9
-rw-r--r--src/modules/mircimport/pics/kvi_mircimport.pngbin0 -> 733 bytes
7 files changed, 508 insertions, 0 deletions
diff --git a/src/modules/mircimport/Makefile.am b/src/modules/mircimport/Makefile.am
new file mode 100644
index 00000000..d47e88c7
--- /dev/null
+++ b/src/modules/mircimport/Makefile.am
@@ -0,0 +1,22 @@
+###############################################################################
+# KVirc IRC client Makefile- 10.03.2000 Szymon Stefanek <stefanek@tin.it>
+###############################################################################
+
+AM_CPPFLAGS = -I$(SS_TOPSRCDIR)/src/kvilib/include/ -I$(SS_TOPSRCDIR)/src/kvirc/include/ \
+$(SS_INCDIRS) $(SS_CPPFLAGS) -DGLOBAL_KVIRC_DIR=\"$(globalkvircdir)\"
+
+SUBDIRS = caps pics
+
+pluglib_LTLIBRARIES = libkvimircimport.la
+
+libkvimircimport_la_LDFLAGS = -module -avoid-version $(SS_LDFLAGS) $(SS_LIBDIRS)
+
+libkvimircimport_la_SOURCES = libkvimircimport.cpp
+libkvimircimport_la_LIBADD = $(SS_LIBLINK) ../../kvilib/build/libkvilib.la
+
+noinst_HEADERS= libkvimircimport.h
+
+%.moc: %.h
+ $(SS_QT_MOC) $< -o $@
+
+libkvimircimport.cpp: libkvimircimport.moc
diff --git a/src/modules/mircimport/caps/Makefile.am b/src/modules/mircimport/caps/Makefile.am
new file mode 100644
index 00000000..151a1e0a
--- /dev/null
+++ b/src/modules/mircimport/caps/Makefile.am
@@ -0,0 +1,9 @@
+###############################################################################
+# KVirc IRC client Makefile - 10.03.2000 Szymon Stefanek <stefanek@tin.it>
+###############################################################################
+
+tmpdir = $(pluglibdir)/caps/serverimport/
+
+tmp_DATA= mircimport
+
+EXTRA_DIST = $(tmp_DATA)
diff --git a/src/modules/mircimport/caps/mircimport b/src/modules/mircimport/caps/mircimport
new file mode 100644
index 00000000..9788f702
--- /dev/null
+++ b/src/modules/mircimport/caps/mircimport
@@ -0,0 +1 @@
+timestamp
diff --git a/src/modules/mircimport/libkvimircimport.cpp b/src/modules/mircimport/libkvimircimport.cpp
new file mode 100644
index 00000000..4f3ac568
--- /dev/null
+++ b/src/modules/mircimport/libkvimircimport.cpp
@@ -0,0 +1,385 @@
+//
+// File : libkvimircimport.cpp
+// Creation date : Tue Aug 27 01:20:35 2002 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#include "libkvimircimport.h"
+#include "kvi_module.h"
+
+#include "kvi_filedialog.h"
+#include "kvi_fileutils.h"
+#include "kvi_locale.h"
+#include "kvi_config.h"
+#include "kvi_app.h"
+#include "kvi_qstring.h"
+
+
+#include <qmessagebox.h>
+#include <qdir.h>
+#include <qpushbutton.h>
+#include "kvi_tal_vbox.h"
+
+KviMircServersIniImport * g_pMircServersIniImport = 0;
+KviRemoteMircServersIniImport * g_pRemoteMircServersIniImport = 0;
+
+
+KviMircServersIniImport::KviMircServersIniImport(KviModuleExtensionDescriptor * d)
+: KviMexServerImport(d)
+{
+}
+
+KviMircServersIniImport::~KviMircServersIniImport()
+{
+ g_pMircServersIniImport = 0;
+}
+
+int KviMircServersIniImport::doImport(const QString& filename)
+{
+ KviConfig cfg(filename,KviConfig::Read,true);
+ int iCount = 0;
+ if(cfg.hasGroup("servers"))
+ {
+ cfg.setGroup("servers");
+ int i = 0;
+ QString key;
+ QString entry;
+ do {
+ KviQString::sprintf(key,"n%d",i);
+ entry = cfg.readEntry(key,"");
+ if(!entry.isEmpty())
+ {
+ QString description;
+ QString serv;
+ QString port;
+ kvi_u32_t uPort = 0;
+ // <description>SERVER:<server:port>GROUP:<network>
+ int idx = KviQString::find(entry,"SERVER:");
+ if(idx != -1)
+ {
+ description = entry.left(idx);
+ entry.remove(0,idx + 7);
+ idx = KviQString::find(entry,"GROUP:");
+ if(idx != -1)
+ {
+ port = entry.left(idx);
+ entry.remove(0,idx + 6);
+ }
+ idx = KviQString::find(port,':');
+ if(idx != -1)
+ {
+ serv = port.left(idx);
+ port.remove(0,idx + 1);
+ bool bOk;
+ uPort = port.toUInt(&bOk);
+ if(!bOk)uPort = 6667;
+ } else {
+ serv = port;
+ uPort = 6667;
+ }
+ }
+ if(entry.isEmpty())entry = __tr("Standalone Servers");
+ if(!serv.isEmpty())
+ {
+ KviIrcServer s;
+ s.m_szHostname = serv;
+ s.m_szDescription = description;
+ s.m_uPort = uPort;
+ iCount++;
+ emit server(s,entry);
+ }
+ ++i;
+ }
+ } while(!entry.isEmpty());
+ } else {
+ QString tmp;
+ KviQString::sprintf(tmp,__tr2qs("%Q doesn't look like a servers.ini file.\nImport failed."),&filename);
+ QMessageBox::warning(0,__tr2qs("Warning - KVIrc"),tmp);
+ }
+ return iCount;
+}
+
+void KviMircServersIniImport::start()
+{
+ //KviStr buffer;
+ QString buffer;
+ if(!KviFileDialog::askForOpenFileName(buffer,__tr("Choose a servers.ini file"),0,"*.ini",false,true))return;
+
+ doImport(buffer);
+ delete this;
+}
+
+void KviMircServersIniImport::die()
+{
+ delete this;
+}
+
+
+
+
+
+
+
+#define KVI_WWWMIRCCOUK_SERVERSINI "http://www.mirc.co.uk/servers.ini"
+
+
+
+KviRemoteMircServerImportWizard::KviRemoteMircServerImportWizard(KviRemoteMircServersIniImport * f)
+: KviTalWizard(0)
+{
+ QString capt = __tr2qs("Remote mIRC servers.ini Import Wizard");
+ setCaption(capt);
+
+
+ m_pRequest = 0;
+ m_pFilter = f;
+
+ QLabel * l = new QLabel(this);
+ l->setText(__tr2qs("<center><b>Welcome!</b><br><br>This wizard will guide you in the process of " \
+ "downloading a list of IRC servers. Please click \"<b>Next</b>\" to begin the operation.</center>"));
+ addPage(l,capt);
+
+
+ KviTalVBox * vb = new KviTalVBox(this);
+ l = new QLabel(vb);
+ l->setText(__tr2qs("<center>Here you can modify the URL that the list will be downloaded from. In most cases the default URL is acceptable.</center>"));
+
+ vb->setStretchFactor(l,1);
+
+ m_pUrlEdit = new QLineEdit(vb);
+
+ m_pUrlEdit->setText(KVI_WWWMIRCCOUK_SERVERSINI);
+
+ addPage(vb,__tr2qs("URL Selection"));
+
+ vb = new KviTalVBox(this);
+
+ l = new QLabel(__tr2qs("Please wait while the list is being downloaded"),vb);
+ vb->setStretchFactor(l,1);
+
+ m_pOutput = new QLabel(vb);
+ m_pOutput->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
+
+ addPage(vb,__tr2qs("List Download"));
+
+ setBackEnabled(vb,false);
+ setNextEnabled(vb,false);
+ setFinishEnabled(vb,true);
+
+ connect(this,SIGNAL(selected(const QString &)),this,SLOT(pageSelected(const QString &)));
+}
+
+KviRemoteMircServerImportWizard::~KviRemoteMircServerImportWizard()
+{
+ if(m_pRequest)delete m_pRequest;
+}
+
+void KviRemoteMircServerImportWizard::pageSelected(const QString &title)
+{
+ if(title == __tr2qs("List Download"))
+ {
+ start();
+ }
+}
+
+void KviRemoteMircServerImportWizard::closeEvent(QCloseEvent *)
+{
+ m_pFilter->die();
+}
+
+void KviRemoteMircServerImportWizard::done(int r)
+{
+ m_pFilter->die();
+}
+
+
+void KviRemoteMircServerImportWizard::start()
+{
+ QString url = m_pUrlEdit->text();
+ if(url.isEmpty())url = KVI_WWWMIRCCOUK_SERVERSINI;
+
+ finishButton()->setEnabled(false);
+ if(m_pRequest)delete m_pRequest;
+
+ m_pRequest = new KviHttpRequest();
+ connect(m_pRequest,SIGNAL(terminated(bool)),this,SLOT(getListTerminated(bool)));
+ connect(m_pRequest,SIGNAL(status(const QString &)),this,SLOT(getListMessage(const QString &)));
+
+ g_pApp->getTmpFileName(m_szTmpFileName,"servers.ini");
+ if(!m_pRequest->get(KviUrl(url),KviHttpRequest::StoreToFile,m_szTmpFileName))
+ {
+ delete m_pRequest;
+ m_pRequest = 0;
+ m_pOutput->setText(__tr2qs("Failed to start the server list transfer :("));
+ finishButton()->setEnabled(true);
+ }
+}
+
+void KviRemoteMircServerImportWizard::getListMessage(const QString &message)
+{
+ if(!message.isEmpty())m_pOutput->setText(message);
+}
+
+
+void KviRemoteMircServerImportWizard::getListTerminated(bool bSuccess)
+{
+ if(!m_pRequest)return;
+ if(bSuccess)
+ {
+ m_pOutput->setText(__tr2qs("File downloaded: processing ..."));
+ m_pOutput->repaint();
+#ifndef COMPILE_ON_WINDOWS
+ g_pApp->syncX();
+#endif //!COMPILE_ON_WINDOWS
+
+ int iCount = m_pFilter->doImport(m_szTmpFileName);
+
+ QString tmp;
+ if(iCount > 0)
+ tmp = __tr2qs("%1 servers imported succesfully").arg(iCount);
+ else
+ tmp = __tr2qs("No servers imported");
+ m_pOutput->setText(tmp);
+
+ QDir d;
+ d.remove(m_szTmpFileName);
+ } else m_pOutput->setText(m_pRequest->lastError());
+
+ delete m_pRequest;
+ m_pRequest = 0;
+ cancelButton()->setEnabled(false);
+ finishButton()->setEnabled(true);
+}
+
+
+KviRemoteMircServersIniImport::KviRemoteMircServersIniImport(KviModuleExtensionDescriptor * d)
+: KviMircServersIniImport(d)
+{
+ m_pWizard = 0;
+}
+
+KviRemoteMircServersIniImport::~KviRemoteMircServersIniImport()
+{
+ if(m_pWizard)delete m_pWizard;
+ g_pRemoteMircServersIniImport = 0;
+}
+
+void KviRemoteMircServersIniImport::start()
+{
+ if(m_pWizard)delete m_pWizard;
+ m_pWizard = new KviRemoteMircServerImportWizard(this);
+ m_pWizard->show();
+}
+
+void KviRemoteMircServersIniImport::die()
+{
+ delete this;
+}
+
+
+static KviModuleExtension * mircimport_local_filter_alloc(KviModuleExtensionAllocStruct * s)
+{
+ if(g_pMircServersIniImport)delete g_pMircServersIniImport;
+ g_pMircServersIniImport = new KviMircServersIniImport(s->pDescriptor);
+ return g_pMircServersIniImport;
+}
+
+static KviModuleExtension * mircimport_remote_filter_alloc(KviModuleExtensionAllocStruct * s)
+{
+ if(g_pRemoteMircServersIniImport)delete g_pRemoteMircServersIniImport;
+ g_pRemoteMircServersIniImport = new KviRemoteMircServersIniImport(s->pDescriptor);
+ return g_pRemoteMircServersIniImport;
+}
+
+static bool mircimport_module_init(KviModule * m)
+{
+ QString szPath;
+ QPixmap * pix = 0;
+ if(g_pApp->findImage(szPath,"kvi_mircimport.png"))
+ {
+ pix = new QPixmap(szPath);
+ if(pix->isNull())
+ {
+ delete pix;
+ pix = 0;
+ }
+ }
+
+ KviModuleExtensionDescriptor * d = m->registerExtension("serverimport",
+ "mIRC servers.ini import filter",
+ __tr("Import from servers.ini"),
+ mircimport_local_filter_alloc);
+
+ if(d && pix)d->setIcon(*pix);
+
+ d = m->registerExtension("serverimport",
+ "Remote mIRC servers.ini import filter",
+ __tr("Import from http://www.mirc.co.uk/servers.ini"),
+ mircimport_remote_filter_alloc);
+
+ if(d && pix)d->setIcon(*pix);
+
+ if(pix)delete pix;
+ return true;
+}
+
+static bool mircimport_module_cleanup(KviModule *m)
+{
+ if(g_pMircServersIniImport)delete g_pMircServersIniImport;
+ if(g_pRemoteMircServersIniImport)delete g_pRemoteMircServersIniImport;
+ g_pMircServersIniImport = 0;
+ g_pRemoteMircServersIniImport = 0;
+
+ return true;
+}
+
+static bool mircimport_module_can_unload(KviModule * m)
+{
+ return ((!g_pMircServersIniImport) && (!g_pRemoteMircServersIniImport));
+}
+
+/*
+KVIMODULEEXPORTFUNC KviIrcServerImport * mircimport_module_createIrcServerImport(const char *filterName)
+{
+ if(kvi_strEqualCI(filterName,__tr("Import from servers.ini")))
+ {
+ if(!g_pMircServersIniImport)g_pMircServersIniImport = new KviMircServersIniImport();
+ return g_pMircServersIniImport;
+ } else {
+ if(!g_pRemoteMircServersIniImport)g_pRemoteMircServersIniImport = new KviRemoteMircServersIniImport("http://www.mirc.co.uk/servers.ini");
+ return g_pRemoteMircServersIniImport;
+ }
+ return 0;
+}
+*/
+
+
+
+KVIRC_MODULE(
+ "File", // module name
+ "1.0.0", // module version
+ "Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)", // author & (C)
+ "mIRC servers.ini importer",
+ mircimport_module_init,
+ mircimport_module_can_unload,
+ 0,
+ mircimport_module_cleanup
+)
+
+#include "libkvimircimport.moc"
diff --git a/src/modules/mircimport/libkvimircimport.h b/src/modules/mircimport/libkvimircimport.h
new file mode 100644
index 00000000..360e8346
--- /dev/null
+++ b/src/modules/mircimport/libkvimircimport.h
@@ -0,0 +1,82 @@
+#ifndef _LIBKVIMIRCIMPORT_H_
+#define _LIBKVIMIRCIMPORT_H_
+//
+// File : libkvimircimport.h
+// Creation date : Tue Aug 27 01:28:02 2002 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#include "kvi_mexserverimport.h"
+#include "kvi_string.h"
+#include "kvi_http.h"
+
+#include <kvi_tal_wizard.h>
+#include <qlineedit.h>
+#include <qlabel.h>
+
+class KviMircServersIniImport : public KviMexServerImport
+{
+ Q_OBJECT
+public:
+ KviMircServersIniImport(KviModuleExtensionDescriptor * d);
+ ~KviMircServersIniImport();
+public:
+ int doImport(const QString& filename);
+ virtual void start();
+ virtual void die();
+};
+
+class KviRemoteMircServerImportWizard;
+
+class KviRemoteMircServersIniImport : public KviMircServersIniImport
+{
+ Q_OBJECT
+public:
+ KviRemoteMircServersIniImport(KviModuleExtensionDescriptor * d);
+ ~KviRemoteMircServersIniImport();
+protected:
+ KviRemoteMircServerImportWizard * m_pWizard;
+public:
+ virtual void start();
+ virtual void die();
+};
+
+class KviRemoteMircServerImportWizard : public KviTalWizard
+{
+ Q_OBJECT
+public:
+ KviRemoteMircServerImportWizard(KviRemoteMircServersIniImport * f);
+ ~KviRemoteMircServerImportWizard();
+protected:
+ QLineEdit * m_pUrlEdit;
+ QLabel * m_pOutput;
+ KviRemoteMircServersIniImport * m_pFilter;
+ KviHttpRequest * m_pRequest;
+ QString m_szTmpFileName;
+protected:
+ virtual void closeEvent(QCloseEvent *e);
+ virtual void done(int r);
+ void start();
+protected slots:
+ void getListMessage(const QString &message);
+ void getListTerminated(bool bSuccess);
+ void pageSelected(const QString &title);
+};
+
+#endif //_LIBKVIMIRCIMPORT_H_
diff --git a/src/modules/mircimport/pics/Makefile.am b/src/modules/mircimport/pics/Makefile.am
new file mode 100644
index 00000000..839e9668
--- /dev/null
+++ b/src/modules/mircimport/pics/Makefile.am
@@ -0,0 +1,9 @@
+###############################################################################
+# KVirc IRC client Makefile - 10.03.2000 Szymon Stefanek <stefanek@tin.it>
+###############################################################################
+
+tmpdir = $(picsdir)
+
+tmp_DATA= kvi_mircimport.png
+
+EXTRA_DIST = $(tmp_DATA)
diff --git a/src/modules/mircimport/pics/kvi_mircimport.png b/src/modules/mircimport/pics/kvi_mircimport.png
new file mode 100644
index 00000000..e671256f
--- /dev/null
+++ b/src/modules/mircimport/pics/kvi_mircimport.png
Binary files differ