summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc/mainwindow.cpp
blob: 3d13ee9fd1d16321f00af924c8d055f02c7615e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <qpe/qpemenubar.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpopupmenu.h>

#include "mainwindow.h"
#include "ircservertab.h"
#include "ircserverlist.h"

MainWindow::MainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f) {
    setCaption(tr("IRC Client"));
    m_tabWidget = new QTabWidget(this);
    connect(m_tabWidget, SIGNAL(currentChanged(QWidget *)), this, SLOT(tabSelected(QWidget *)));
    setCentralWidget(m_tabWidget);
    setToolBarsMovable(FALSE);
    QPEMenuBar *menuBar = new QPEMenuBar(this);
    QPopupMenu *irc = new QPopupMenu(this);
    menuBar->insertItem(tr("IRC"), irc);
    QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0);
    connect(a, SIGNAL(activated()), this, SLOT(newConnection()));
    a->addTo(irc);
    
    m_joinAction = new QAction(tr("Join channel"), Resource::loadPixmap("forward"), QString::null, 0, this, 0);
    m_joinAction->setEnabled(FALSE);
    connect(m_joinAction, SIGNAL(activated()), this, SLOT(join()));
    m_joinAction->addTo(irc);
}

void MainWindow::tabSelected(QWidget *) {
    m_joinAction->setEnabled(TRUE);
}

void MainWindow::closeTab() {
    /* Does not directly close the tab but triggers an action
       which at some point will close the tab using a callback */
    IRCTab *tab = (IRCTab *)m_tabWidget->currentPage();
    if (tab) {
        tab->remove();
    }
}

void MainWindow::join() {
    IRCTab *tab = (IRCTab *)m_tabWidget->currentPage();
    if (tab) {
        tab->session()->join("#opie.de");
    }
}

void MainWindow::addTab(IRCTab *tab) {
    m_tabWidget->addTab(tab, tab->title());
    m_tabWidget->showPage(tab);
    tabSelected(tab);
}

void MainWindow::killTab(IRCTab *tab) {
    m_tabWidget->removePage(tab);
    /* there might be nicer ways to do this .. */
    delete tab;
}

void MainWindow::newConnection() {
    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();
    }
}