summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc/mainwindow.cpp
Unidiff
Diffstat (limited to 'noncore/net/opieirc/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/mainwindow.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp
index 1811a0c..3d60107 100644
--- a/noncore/net/opieirc/mainwindow.cpp
+++ b/noncore/net/opieirc/mainwindow.cpp
@@ -1,139 +1,159 @@
1#include <qmenubar.h> 1#include <qmenubar.h>
2#include <qpe/resource.h> 2#include <qpe/resource.h>
3 3
4#include <opie2/odebug.h> 4#include <opie2/odebug.h>
5 5
6#include <qwhatsthis.h> 6#include <qwhatsthis.h>
7 7
8#include "mainwindow.h" 8#include "mainwindow.h"
9#include "ircservertab.h" 9#include "ircservertab.h"
10#include "dcctransfertab.h"
10#include "ircserverlist.h" 11#include "ircserverlist.h"
11#include "ircsettings.h" 12#include "ircsettings.h"
12 13
14#include <stdio.h>
15
16
13QString MainWindow::appCaption() { 17QString MainWindow::appCaption() {
14 return QObject::tr("Opie IRC"); 18 return QObject::tr("Opie IRC");
15} 19}
16 20
17 21
18MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { 22MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) {
19 setCaption(tr("IRC Client")); 23 setCaption(tr("IRC Client"));
20 m_tabWidget = new IRCTabWidget(this); 24 m_tabWidget = new IRCTabWidget(this);
21 QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here")); 25 QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here"));
22 connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selected(QWidget*))); 26 connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selected(QWidget*)));
23 setCentralWidget(m_tabWidget); 27 setCentralWidget(m_tabWidget);
24 setToolBarsMovable(FALSE); 28 setToolBarsMovable(FALSE);
25 QMenuBar *menuBar = new QMenuBar(this); 29 QMenuBar *menuBar = new QMenuBar(this);
26 QPopupMenu *irc = new QPopupMenu(this); 30 QPopupMenu *irc = new QPopupMenu(this);
27 menuBar->insertItem(tr("IRC"), irc); 31 menuBar->insertItem(tr("IRC"), irc);
28 QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); 32 QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0);
29 connect(a, SIGNAL(activated()), this, SLOT(newConnection())); 33 connect(a, SIGNAL(activated()), this, SLOT(newConnection()));
30 a->setWhatsThis(tr("Create a new connection to an IRC server")); 34 a->setWhatsThis(tr("Create a new connection to an IRC server"));
31 a->addTo(irc); 35 a->addTo(irc);
32 a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0); 36 a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0);
33 a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance")); 37 a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance"));
34 connect(a, SIGNAL(activated()), this, SLOT(settings())); 38 connect(a, SIGNAL(activated()), this, SLOT(settings()));
35 a->addTo(irc); 39 a->addTo(irc);
40 m_dccTab = 0;
36 loadSettings(); 41 loadSettings();
37} 42}
38 43
39/*IRCTabWidget MainWindow::getTabWidget(){ 44/*IRCTabWidget MainWindow::getTabWidget(){
40 return m_tabWidget; 45 return m_tabWidget;
41} */ 46} */
42 47
43void MainWindow::loadSettings() { 48void MainWindow::loadSettings() {
44 Config config("OpieIRC"); 49 Config config("OpieIRC");
45 config.setGroup("OpieIRC"); 50 config.setGroup("OpieIRC");
46 IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF"); 51 IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF");
47 IRCTab::m_textColor = config.readEntry("TextColor", "#000000"); 52 IRCTab::m_textColor = config.readEntry("TextColor", "#000000");
48 IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000"); 53 IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000");
49 IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000"); 54 IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000");
50 IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB"); 55 IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB");
51 IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF"); 56 IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF");
52 IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300"); 57 IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300");
53 IRCTab::m_maxLines = config.readNumEntry("Lines", 100); 58 IRCTab::m_maxLines = config.readNumEntry("Lines", 100);
54 IRCTab::setUseTimeStamps( config.readBoolEntry("DisplayTime", false ) ); 59 IRCTab::setUseTimeStamps( config.readBoolEntry("DisplayTime", false ) );
55} 60}
56 61
57void MainWindow::selected(QWidget *) { 62void MainWindow::selected(QWidget *) {
58 m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black); 63 m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black);
59 emit updateScroll(); 64 emit updateScroll();
60} 65}
61 66
62void MainWindow::addTab(IRCTab *tab) { 67void MainWindow::addTab(IRCTab *tab) {
63 connect(tab, SIGNAL(changed(IRCTab*)), this, SLOT(changeEvent(IRCTab*))); 68 connect(tab, SIGNAL(changed(IRCTab*)), this, SLOT(changeEvent(IRCTab*)));
64 connect(tab, SIGNAL(ping (const QString&)), this, SLOT(slotPing(const QString&))); 69 connect(tab, SIGNAL(ping (const QString&)), this, SLOT(slotPing(const QString&)));
65 connect(tab, SIGNAL(nextTab()), this, SLOT(slotNextTab())); 70 connect(tab, SIGNAL(nextTab()), this, SLOT(slotNextTab()));
66 connect(tab, SIGNAL(prevTab()), this, SLOT(slotPrevTab())); 71 connect(tab, SIGNAL(prevTab()), this, SLOT(slotPrevTab()));
67 72
68 m_tabWidget->addTab(tab, tab->title()); 73 m_tabWidget->addTab(tab, tab->title());
69 m_tabWidget->showPage(tab); 74 m_tabWidget->showPage(tab);
70 tab->setID(m_tabWidget->currentPageIndex()); 75 tab->setID(m_tabWidget->currentPageIndex());
71 m_tabs.append(tab); 76 m_tabs.append(tab);
72} 77}
73 78
74void MainWindow::changeEvent(IRCTab *tab) { 79void MainWindow::changeEvent(IRCTab *tab) {
75 if (tab->id() != m_tabWidget->currentPageIndex()) 80 if (tab->id() != m_tabWidget->currentPageIndex())
76 m_tabWidget->setTabColor(tab->id(), blue); 81 m_tabWidget->setTabColor(tab->id(), blue);
77} 82}
78 83
79void MainWindow::killTab(IRCTab *tab, bool imediate) { 84void MainWindow::killTab(IRCTab *tab, bool imediate) {
85 if (tab == m_dccTab)
86 m_dccTab = 0;
87
80 m_toDelete.append( tab ); 88 m_toDelete.append( tab );
81 89
82 if ( imediate ) 90 if ( imediate )
83 slotKillTabsLater(); 91 slotKillTabsLater();
84 else 92 else
85 QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) ); 93 QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) );
86} 94}
87 95
88void MainWindow::slotKillTabsLater() { 96void MainWindow::slotKillTabsLater() {
89 for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) { 97 for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) {
90 m_tabWidget->removePage( it.current() ); 98 m_tabWidget->removePage( it.current() );
91 odebug << it.current() << oendl; 99 odebug << it.current() << oendl;
92 m_tabs.remove( it.current() ); 100 m_tabs.remove( it.current() );
93 } 101 }
94 102
95 m_toDelete.setAutoDelete( true ); 103 m_toDelete.setAutoDelete( true );
96 m_toDelete.clear(); 104 m_toDelete.clear();
97 m_toDelete.setAutoDelete( false ); 105 m_toDelete.setAutoDelete( false );
98} 106}
99 107
100void MainWindow::newConnection() { 108void MainWindow::newConnection() {
101 IRCServerList list(this, "ServerList", TRUE); 109 IRCServerList list(this, "ServerList", TRUE);
102 if (list.exec() == QDialog::Accepted && list.hasServer()) { 110 if (list.exec() == QDialog::Accepted && list.hasServer()) {
103 IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget); 111 IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget);
104 addTab(serverTab); 112 addTab(serverTab);
105 serverTab->doConnect(); 113 serverTab->doConnect();
106 } 114 }
107} 115}
108 116
109void MainWindow::settings() { 117void MainWindow::settings() {
110 IRCSettings settings(this, "Settings", TRUE); 118 IRCSettings settings(this, "Settings", TRUE);
111 if (settings.exec() == QDialog::Accepted) { 119 if (settings.exec() == QDialog::Accepted) {
112 QListIterator<IRCTab> it(m_tabs); 120 QListIterator<IRCTab> it(m_tabs);
113 for (; it.current(); ++it) { 121 for (; it.current(); ++it) {
114 /* Inform all tabs about the new settings */ 122 /* Inform all tabs about the new settings */
115 it.current()->settingsChanged(); 123 it.current()->settingsChanged();
116 } 124 }
117 } 125 }
118} 126}
119 127
120 128
121void MainWindow::slotNextTab() { 129void MainWindow::slotNextTab() {
122 int i = m_tabWidget->currentPageIndex (); 130 int i = m_tabWidget->currentPageIndex ();
123 m_tabWidget->setCurrentPage ( i+1 ); 131 m_tabWidget->setCurrentPage ( i+1 );
124 132
125 int j = m_tabWidget->currentPageIndex (); 133 int j = m_tabWidget->currentPageIndex ();
126 if ( i == j ) 134 if ( i == j )
127 m_tabWidget->setCurrentPage ( 1 ); 135 m_tabWidget->setCurrentPage ( 1 );
128} 136}
129 137
130void MainWindow::slotPrevTab() { 138void MainWindow::slotPrevTab() {
131 int i = m_tabWidget->currentPageIndex (); 139 int i = m_tabWidget->currentPageIndex ();
132 if ( i > 1 ) 140 if ( i > 1 )
133 m_tabWidget->setCurrentPage ( i-1 ); 141 m_tabWidget->setCurrentPage ( i-1 );
134} 142}
135 143
136void MainWindow::slotPing( const QString& /*channel*/ ) { 144void MainWindow::slotPing( const QString& /*channel*/ ) {
137 raise(); 145 raise();
138} 146}
139 147
148void MainWindow::addDCC(DCCTransfer::Type type, Q_UINT32 ip4Addr, Q_UINT16 port,
149 const QString &filename, const QString &nickname, unsigned int size) {
150
151 if (!m_dccTab) {
152 m_dccTab = new DCCTransferTab(this);
153 addTab(m_dccTab);
154 m_dccTab->show();
155 }
156
157 m_dccTab->addTransfer(type, ip4Addr, port, filename, nickname, size);
158}
159