Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mainwindow.cpp

Go to the documentation of this file.
00001 
00002 #include <opie2/odebug.h>
00003 #include <opie2/oresource.h>
00004 
00005 #include <qmenubar.h>
00006 #include <qwhatsthis.h>
00007 
00008 #include "mainwindow.h"
00009 #include "ircservertab.h"
00010 #include "dcctransfertab.h"
00011 #include "ircserverlist.h"
00012 #include "ircsettings.h"
00013 
00014 #include <stdio.h>
00015 
00016 
00017 QString MainWindow::appCaption() {
00018     return QObject::tr("Opie IRC");
00019 }
00020 
00021 
00022 MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) {
00023     setCaption(tr("IRC Client"));
00024     m_tabWidget = new IRCTabWidget(this);
00025     QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here"));
00026     connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selected(QWidget*)));
00027     setCentralWidget(m_tabWidget);
00028     setToolBarsMovable(FALSE);
00029     QMenuBar *menuBar = new QMenuBar(this);
00030     QPopupMenu *irc = new QPopupMenu(this);
00031     menuBar->insertItem(tr("IRC"), irc);
00032     QAction *a = new QAction( tr("New connection"),
00033                               Opie::Core::OResource::loadPixmap( "pass", Opie::Core::OResource::SmallIcon ),
00034                               QString::null, 0, this, 0 );
00035     connect(a, SIGNAL(activated()), this, SLOT(newConnection()));
00036     a->setWhatsThis(tr("Create a new connection to an IRC server"));
00037     a->addTo(irc);
00038     a = new QAction( tr("Settings"),
00039                      Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ),
00040                      QString::null, 0, this, 0 );
00041     a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance"));
00042     connect(a, SIGNAL(activated()), this, SLOT(settings()));
00043     a->addTo(irc);
00044     m_dccTab = 0;
00045     loadSettings();
00046 }
00047 
00048 /*IRCTabWidget MainWindow::getTabWidget(){
00049   return m_tabWidget;
00050 } */
00051 
00052 void MainWindow::loadSettings() {
00053     Config config("OpieIRC");
00054     config.setGroup("OpieIRC");
00055     IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF");
00056     IRCTab::m_textColor = config.readEntry("TextColor", "#000000");
00057     IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000");
00058     IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000");
00059     IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB");
00060     IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF");
00061     IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300");
00062     IRCTab::m_maxLines = config.readNumEntry("Lines", 100);
00063     IRCTab::setUseTimeStamps( config.readBoolEntry("DisplayTime", false ) );
00064 }
00065 
00066 void MainWindow::selected(QWidget *) {
00067     m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black);
00068     emit updateScroll();
00069 }
00070 
00071 void MainWindow::addTab(IRCTab *tab) {
00072     connect(tab, SIGNAL(changed(IRCTab*)), this, SLOT(changeEvent(IRCTab*)));
00073     connect(tab, SIGNAL(ping (const QString&)), this, SLOT(slotPing(const QString&)));
00074     connect(tab, SIGNAL(nextTab()), this, SLOT(slotNextTab()));
00075     connect(tab, SIGNAL(prevTab()), this, SLOT(slotPrevTab()));
00076 
00077     m_tabWidget->addTab(tab, tab->title());
00078     m_tabWidget->showPage(tab);
00079     tab->setID(m_tabWidget->currentPageIndex());
00080     m_tabs.append(tab);
00081 }
00082 
00083 void MainWindow::changeEvent(IRCTab *tab) {
00084     if (tab->id() != m_tabWidget->currentPageIndex())
00085         m_tabWidget->setTabColor(tab->id(), blue);
00086 }
00087 
00088 void MainWindow::killTab(IRCTab *tab, bool imediate) {
00089     if (tab == m_dccTab)
00090         m_dccTab = 0;
00091     
00092     m_toDelete.append( tab );
00093 
00094     if ( imediate )
00095         slotKillTabsLater();
00096     else
00097         QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) );
00098 }
00099 
00100 void MainWindow::slotKillTabsLater() {
00101     for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) {
00102         m_tabWidget->removePage( it.current() );
00103         odebug << it.current() << oendl;
00104         m_tabs.remove( it.current() );
00105     }
00106 
00107     m_toDelete.setAutoDelete( true );
00108     m_toDelete.clear();
00109     m_toDelete.setAutoDelete( false );
00110 }
00111 
00112 void MainWindow::newConnection() {
00113     IRCServerList list(this, "ServerList", TRUE);
00114     if (list.exec() == QDialog::Accepted && list.hasServer()) {
00115         IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget);
00116         addTab(serverTab);
00117         serverTab->doConnect();
00118     }
00119 }
00120 
00121 void MainWindow::settings() {
00122     IRCSettings settings(this, "Settings", TRUE);
00123     if (settings.exec() == QDialog::Accepted) {
00124         QListIterator<IRCTab> it(m_tabs);
00125         for (; it.current(); ++it) {
00126             /* Inform all tabs about the new settings */
00127             it.current()->settingsChanged();
00128         }
00129     }
00130 }
00131 
00132 
00133 void MainWindow::slotNextTab() {
00134     int i = m_tabWidget->currentPageIndex ();
00135     m_tabWidget->setCurrentPage ( i+1 );
00136 
00137     int j = m_tabWidget->currentPageIndex ();
00138     if ( i == j )
00139         m_tabWidget->setCurrentPage ( 1 );
00140 }
00141 
00142 void MainWindow::slotPrevTab() {
00143     int i = m_tabWidget->currentPageIndex ();
00144     if ( i > 1 )
00145         m_tabWidget->setCurrentPage ( i-1 );
00146 }
00147 
00148 void MainWindow::slotPing( const QString& /*channel*/ ) {
00149     raise();
00150 }
00151 
00152 void MainWindow::addDCC(DCCTransfer::Type type, Q_UINT32 ip4Addr, Q_UINT16 port, 
00153         const QString &filename, const QString &nickname, unsigned int size) {
00154     
00155     if (!m_dccTab) {
00156         m_dccTab = new DCCTransferTab(this);
00157         addTab(m_dccTab);
00158         m_dccTab->show();
00159     }
00160     
00161     m_dccTab->addTransfer(type, ip4Addr, port, filename, nickname, size);
00162 }
00163 

Generated on Sat Nov 5 16:15:52 2005 for OPIE by  doxygen 1.4.2