summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/mainwindow.cpp
blob: b2d3a71f27c34838628f8b99dc98feac4e0c883e (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**********************************************************************
** Copyright (C) 2002 Michael 'Mickey' Lauer.  All rights reserved.
**
** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/

#include "configwindow.h"
#include "mainwindow.h"
#include "wellenreiter.h"

#include <qcombobox.h>
#include <qiconset.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qstatusbar.h>
#include <qtoolbutton.h>

#ifdef QWS
#include <qpe/resource.h>
#else
#include "resource.h"
#endif

WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f )
           :QMainWindow( parent, name, f )
{
    cw = new WellenreiterConfigWindow( this );
    mw = new Wellenreiter( this );
    mw->setConfigWindow( cw );
    setCentralWidget( mw );

    // setup icon sets

    infoIconSet = new QIconSet( Resource::loadPixmap( "wellenreiter/InfoIcon" ) );
    settingsIconSet = new QIconSet( Resource::loadPixmap( "wellenreiter/SettingsIcon" ) );
    #ifdef QWS
    searchIconSet = new QIconSet( Resource::loadPixmap( "wellenreiter/SearchIcon" ) );
    cancelIconSet = new QIconSet( Resource::loadPixmap( "wellenreiter/CancelIcon" ) );
    #else
    startStopIconSet = new QIconSet();
    startStopIconSet->setPixmap( Resource::loadPixmap( "wellenreiter/SearchIcon" ), QIconSet::Automatic, QIconSet::Normal, QIconSet::Off );
    startStopIconSet->setPixmap( Resource::loadPixmap( "wellenreiter/CancelIcon" ), QIconSet::Automatic, QIconSet::Normal, QIconSet::On );
    #endif

    // setup tool buttons

    startStopButton = new QToolButton( 0 );
    startStopButton->setAutoRaise( true );
    #ifdef QWS
    startStopButton->setOnIconSet( *cancelIconSet );
    startStopButton->setOffIconSet( *searchIconSet );
    #else
    startStopButton->setIconSet( *startStopIconSet );
    #endif
    startStopButton->setToggleButton( true );
    connect( startStopButton, SIGNAL( clicked() ), mw, SLOT( startStopClicked() ) );
    startStopButton->setEnabled( false );

    QToolButton* c = new QToolButton( 0 );
    c->setAutoRaise( true );
    c->setIconSet( *infoIconSet );
    c->setEnabled( false );

    QToolButton* d = new QToolButton( 0 );
    d->setAutoRaise( true );
    d->setIconSet( *settingsIconSet );
    connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) );

    // setup menu bar

    QMenuBar* mb = menuBar();

    QPopupMenu* file = new QPopupMenu( mb );
    file->insertItem( "&Load" );
    file->insertItem( "&Save" );

    QPopupMenu* view = new QPopupMenu( mb );
    view->insertItem( "&Configure" );

    QPopupMenu* sniffer = new QPopupMenu( mb );
    sniffer->insertItem( "&Configure" );
    sniffer->insertSeparator();

    int id;

    id = mb->insertItem( "&File", file );
    mb->setItemEnabled( id, false );
    id = mb->insertItem( "&View", view );
    mb->setItemEnabled( id, false );
    id = mb->insertItem( "&Sniffer", sniffer );
    mb->setItemEnabled( id, false );

    #ifdef QWS
    mb->insertItem( startStopButton );
    mb->insertItem( c );
    mb->insertItem( d );
    #else // Qt3 changed the insertion order. It's now totally random :(
    mb->insertItem( d );
    mb->insertItem( c );
    mb->insertItem( startStopButton );
    #endif

    // setup status bar (for now only on X11)

    #ifndef QWS
    statusBar()->message( "Ready." );
    #endif

};

void WellenreiterMainWindow::showConfigure()
{
    qDebug( "show configure..." );
    cw->setCaption( tr( "Configure" ) );
    #ifdef QWS
    cw->showMaximized();
    #endif
    int result = cw->exec();

    if ( result )
    {
        // check configuration from config window

        const QString& interface = cw->interfaceName->currentText();
        const int cardtype = cw->daemonDeviceType();
        const int interval = cw->daemonHopInterval();

        if ( ( interface != "<select>" ) && ( cardtype != 0 ) )
            startStopButton->setEnabled( true );
            //TODO ...
        else
            startStopButton->setEnabled( false );
            //TODO ...
    }
}

WellenreiterMainWindow::~WellenreiterMainWindow()
{

    delete infoIconSet;
    delete settingsIconSet;
    #ifdef QWS
    delete searchIconSet;
    delete cancelIconSet;
    #else
    delete startStopIconSet;
    #endif

};