~ubuntu-branches/ubuntu/maverick/kdebase-workspace/maverick-proposed

« back to all changes in this revision

Viewing changes to kdm/kfrontend/kchooser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-07-08 01:11:52 UTC
  • mfrom: (1.1.43 upstream)
  • Revision ID: james.westby@ubuntu.com-20100708011152-z0h26httnjr91mmy
Tags: 4:4.4.92-0ubuntu1
* New upstream rc release:
  - Bump kde-sc-dev-latest to 4.4.92
  - Refresh patches
  - Update symbols
  - plasma-widgets-workspace replaces/conflicts plasma-widget-logout

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
class ChooserListViewItem : public QTreeWidgetItem {
43
43
  public:
44
 
        ChooserListViewItem( QTreeWidget *parent, int _id, const QString &nam, const QString &sts )
45
 
                : QTreeWidgetItem( parent, QStringList() << nam << sts ) { id = _id; }
 
44
    ChooserListViewItem(QTreeWidget *parent, int _id, const QString &nam, const QString &sts)
 
45
        : QTreeWidgetItem(parent, QStringList() << nam << sts) { id = _id; }
46
46
 
47
 
        int id;
 
47
    int id;
48
48
};
49
49
 
50
50
 
51
51
ChooserDlg::ChooserDlg()
52
 
        : inherited()
 
52
    : inherited()
53
53
{
54
 
        completeMenu( LOGIN_REMOTE_ONLY, ex_greet, i18nc("@action:inmenu", "&Local Login"), Qt::ALT+Qt::Key_L );
55
 
 
56
 
        QBoxLayout *vbox = new QVBoxLayout( this );
57
 
 
58
 
        QLabel *title = new QLabel( i18n("XDMCP Host Menu"), this );
59
 
        title->setAlignment( Qt::AlignCenter );
60
 
        vbox->addWidget( title );
61
 
 
62
 
        host_view = new QTreeWidget( this );
63
 
        host_view->setRootIsDecorated( false );
64
 
        host_view->setUniformRowHeights( true );
65
 
        host_view->setEditTriggers( QAbstractItemView::NoEditTriggers );
66
 
        host_view->setColumnCount( 2 );
67
 
        host_view->setHeaderLabels( QStringList()
68
 
                << i18nc("@title:column", "Hostname")
69
 
                << i18nc("@title:column ... of named host", "Status") );
70
 
        host_view->setColumnWidth( 0, fontMetrics().width( "login.domain.com" ) );
71
 
        host_view->setMinimumWidth( fontMetrics().width( "login.domain.com Display not authorized to connect this server" ) );
72
 
        host_view->setAllColumnsShowFocus( true );
73
 
        vbox->addWidget( host_view );
74
 
 
75
 
        iline = new QLineEdit( this );
76
 
        iline->setEnabled( true );
77
 
        QLabel *itxt = new QLabel( i18nc("XDMCP server", "Hos&t:"), this );
78
 
        itxt->setBuddy( iline );
79
 
        QPushButton *addButton = new QPushButton( i18nc("@action:button", "A&dd"), this );
80
 
        connect( addButton, SIGNAL(clicked()), SLOT(addHostname()) );
81
 
        QBoxLayout *hibox = new QHBoxLayout();
82
 
        vbox->addLayout( hibox );
83
 
        hibox->addWidget( itxt );
84
 
        hibox->addWidget( iline );
85
 
        hibox->addWidget( addButton );
86
 
 
87
 
        // Buttons
88
 
        QPushButton *acceptButton = new QPushButton( i18nc("@action:button", "&Accept"), this );
89
 
        acceptButton->setDefault( true );
90
 
        QPushButton *pingButton = new QPushButton( i18nc("@action:button", "&Refresh"), this );
91
 
 
92
 
        QBoxLayout *hbox = new QHBoxLayout();
93
 
        vbox->addLayout( hbox );
94
 
        hbox->setSpacing( 20 );
95
 
        hbox->addWidget( acceptButton );
96
 
        hbox->addWidget( pingButton );
97
 
        hbox->addStretch( 1 );
98
 
 
99
 
        if (optMenu) {
100
 
                QPushButton *menuButton = new QPushButton( i18nc("@action:button", "&Menu"), this );
101
 
                menuButton->setMenu( optMenu );
102
 
                hbox->addWidget( menuButton );
103
 
                hbox->addStretch( 1 );
104
 
        }
105
 
 
106
 
//      QPushButton *helpButton = new QPushButton( i18nc("@action:button", "&Help"), this );
107
 
//      hbox->addWidget( helpButton );
 
54
    completeMenu(LOGIN_REMOTE_ONLY, ex_greet, i18nc("@action:inmenu", "&Local Login"), Qt::ALT + Qt::Key_L);
 
55
 
 
56
    QBoxLayout *vbox = new QVBoxLayout(this);
 
57
 
 
58
    QLabel *title = new QLabel(i18n("XDMCP Host Menu"), this);
 
59
    title->setAlignment(Qt::AlignCenter);
 
60
    vbox->addWidget(title);
 
61
 
 
62
    host_view = new QTreeWidget(this);
 
63
    host_view->setRootIsDecorated(false);
 
64
    host_view->setUniformRowHeights(true);
 
65
    host_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
 
66
    host_view->setColumnCount(2);
 
67
    host_view->setHeaderLabels(QStringList()
 
68
        << i18nc("@title:column", "Hostname")
 
69
        << i18nc("@title:column ... of named host", "Status"));
 
70
    host_view->setColumnWidth(0, fontMetrics().width("login.domain.com"));
 
71
    host_view->setMinimumWidth(fontMetrics().width("login.domain.com Display not authorized to connect this server"));
 
72
    host_view->setAllColumnsShowFocus(true);
 
73
    vbox->addWidget(host_view);
 
74
 
 
75
    iline = new QLineEdit(this);
 
76
    iline->setEnabled(true);
 
77
    QLabel *itxt = new QLabel(i18nc("XDMCP server", "Hos&t:"), this);
 
78
    itxt->setBuddy(iline);
 
79
    QPushButton *addButton = new QPushButton(i18nc("@action:button", "A&dd"), this);
 
80
    connect(addButton, SIGNAL(clicked()), SLOT(addHostname()));
 
81
    QBoxLayout *hibox = new QHBoxLayout();
 
82
    vbox->addLayout(hibox);
 
83
    hibox->addWidget(itxt);
 
84
    hibox->addWidget(iline);
 
85
    hibox->addWidget(addButton);
 
86
 
 
87
    // Buttons
 
88
    QPushButton *acceptButton = new QPushButton(i18nc("@action:button", "&Accept"), this);
 
89
    acceptButton->setDefault(true);
 
90
    QPushButton *pingButton = new QPushButton(i18nc("@action:button", "&Refresh"), this);
 
91
 
 
92
    QBoxLayout *hbox = new QHBoxLayout();
 
93
    vbox->addLayout(hbox);
 
94
    hbox->setSpacing(20);
 
95
    hbox->addWidget(acceptButton);
 
96
    hbox->addWidget(pingButton);
 
97
    hbox->addStretch(1);
 
98
 
 
99
    if (optMenu) {
 
100
        QPushButton *menuButton = new QPushButton(i18nc("@action:button", "&Menu"), this);
 
101
        menuButton->setMenu(optMenu);
 
102
        hbox->addWidget(menuButton);
 
103
        hbox->addStretch(1);
 
104
    }
 
105
 
 
106
//    QPushButton *helpButton = new QPushButton(i18nc("@action:button", "&Help"), this);
 
107
//    hbox->addWidget(helpButton);
108
108
 
109
109
#ifdef WITH_KDM_XCONSOLE
110
 
        if (consoleView)
111
 
                vbox->addWidget( consoleView );
 
110
    if (consoleView)
 
111
        vbox->addWidget(consoleView);
112
112
#endif
113
113
 
114
 
        sn = new QSocketNotifier( rfd, QSocketNotifier::Read, this );
115
 
        connect( sn, SIGNAL(activated( int )), SLOT(slotReadPipe()) );
 
114
    sn = new QSocketNotifier(rfd, QSocketNotifier::Read, this);
 
115
    connect(sn, SIGNAL(activated(int)), SLOT(slotReadPipe()));
116
116
 
117
 
        connect( pingButton, SIGNAL(clicked()), SLOT(pingHosts()) );
118
 
        connect( acceptButton, SIGNAL(clicked()), SLOT(accept()) );
119
 
//      connect( helpButton, SIGNAL(clicked()), SLOT(slotHelp()) );
120
 
        connect( host_view, SIGNAL(itemActivated( QTreeWidgetItem *, int )), SLOT(accept()) );
 
117
    connect(pingButton, SIGNAL(clicked()), SLOT(pingHosts()));
 
118
    connect(acceptButton, SIGNAL(clicked()), SLOT(accept()));
 
119
//    connect(helpButton, SIGNAL(clicked()), SLOT(slotHelp()));
 
120
    connect(host_view, SIGNAL(itemActivated(QTreeWidgetItem *, int)), SLOT(accept()));
121
121
}
122
122
 
123
123
/*
124
124
void ChooserDlg::slotHelp()
125
125
{
126
 
        KMessageBox::information( 0,
127
 
                                  i18n("Choose a host, you want to work on,\n"
128
 
                                       "in the list or add one.\n\n"
129
 
                                       "After this box, you must press cancel\n"
130
 
                                       "in the Host Menu to enter a host. :("));
131
 
        iline->setFocus();
 
126
    KMessageBox::information(0,
 
127
                              i18n("Choose a host, you want to work on,\n"
 
128
                                   "in the list or add one.\n\n"
 
129
                                   "After this box, you must press cancel\n"
 
130
                                   "in the Host Menu to enter a host. :("));
 
131
    iline->setFocus();
132
132
}
133
133
*/
134
134
 
135
135
void ChooserDlg::addHostname()
136
136
{
137
 
        if (!iline->text().isEmpty()) {
138
 
                gSendInt( G_Ch_RegisterHost );
139
 
                gSendStr( iline->text().toLatin1() );
140
 
                iline->clear();
141
 
        }
 
137
    if (!iline->text().isEmpty()) {
 
138
        gSendInt(G_Ch_RegisterHost);
 
139
        gSendStr(iline->text().toLatin1());
 
140
        iline->clear();
 
141
    }
142
142
}
143
143
 
144
144
void ChooserDlg::pingHosts()
145
145
{
146
 
        gSendInt( G_Ch_Refresh );
 
146
    gSendInt(G_Ch_Refresh);
147
147
}
148
148
 
149
149
void ChooserDlg::accept()
150
150
{
151
 
        if (focusWidget() == iline) {
152
 
                if (!iline->text().isEmpty()) {
153
 
                        gSendInt( G_Ch_DirectChoice );
154
 
                        gSendStr( iline->text().toLatin1() );
155
 
                        iline->clear();
156
 
                }
157
 
                return;
158
 
        } else /*if (focusWidget() == host_view)*/ {
159
 
                QTreeWidgetItem *item = host_view->currentItem();
160
 
                if (item) {
161
 
                        gSendInt( G_Ready );
162
 
                        gSendInt( ((ChooserListViewItem *)item)->id );
163
 
                        ::exit( EX_NORMAL );
164
 
                }
165
 
        }
 
151
    if (focusWidget() == iline) {
 
152
        if (!iline->text().isEmpty()) {
 
153
            gSendInt(G_Ch_DirectChoice);
 
154
            gSendStr(iline->text().toLatin1());
 
155
            iline->clear();
 
156
        }
 
157
        return;
 
158
    } else /*if (focusWidget() == host_view)*/ {
 
159
        QTreeWidgetItem *item = host_view->currentItem();
 
160
        if (item) {
 
161
            gSendInt(G_Ready);
 
162
            gSendInt(((ChooserListViewItem *)item)->id);
 
163
            ::exit(EX_NORMAL);
 
164
        }
 
165
    }
166
166
}
167
167
 
168
168
void ChooserDlg::reject()
171
171
 
172
172
QString ChooserDlg::recvStr()
173
173
{
174
 
        char *arr = gRecvStr();
175
 
        if (arr) {
176
 
                QString str = QString::fromLatin1( arr );
177
 
                free( arr );
178
 
                return str;
179
 
        } else
180
 
                return i18nc("hostname or status", "<unknown>"); //krazy:exclude=i18ncheckarg
 
174
    char *arr = gRecvStr();
 
175
    if (arr) {
 
176
        QString str = QString::fromLatin1(arr);
 
177
        free(arr);
 
178
        return str;
 
179
    } else
 
180
        return i18nc("hostname or status", "<unknown>"); //krazy:exclude=i18ncheckarg
181
181
}
182
182
 
183
 
ChooserListViewItem *ChooserDlg::findItem( int id )
 
183
ChooserListViewItem *ChooserDlg::findItem(int id)
184
184
{
185
 
        for (int i = 0, rc = host_view->model()->rowCount(); i < rc; i++) {
186
 
                ChooserListViewItem *itm = static_cast<ChooserListViewItem *>(
187
 
                        host_view->topLevelItem( i ));
188
 
                if (itm->id == id)
189
 
                        return itm;
190
 
        }
191
 
        return 0;
 
185
    for (int i = 0, rc = host_view->model()->rowCount(); i < rc; i++) {
 
186
        ChooserListViewItem *itm = static_cast<ChooserListViewItem *>(
 
187
            host_view->topLevelItem(i));
 
188
        if (itm->id == id)
 
189
            return itm;
 
190
    }
 
191
    return 0;
192
192
}
193
193
 
194
194
void ChooserDlg::slotReadPipe()
195
195
{
196
 
        int id;
197
 
        QString nam, sts;
 
196
    int id;
 
197
    QString nam, sts;
198
198
 
199
 
        int cmd = gRecvInt();
200
 
        switch (cmd) {
201
 
        case G_Ch_AddHost:
202
 
        case G_Ch_ChangeHost:
203
 
                id = gRecvInt();
204
 
                nam = recvStr();
205
 
                sts = recvStr();
206
 
                gRecvInt(); /* swallow willing for now */
207
 
                if (cmd == G_Ch_AddHost)
208
 
                        new ChooserListViewItem( host_view, id, nam, sts );
209
 
                else {
210
 
                        QTreeWidgetItem *itm = findItem( id );
211
 
                        itm->setText( 0, nam );
212
 
                        itm->setText( 1, sts );
213
 
                }
214
 
                break;
215
 
        case G_Ch_RemoveHost:
216
 
                delete findItem( gRecvInt() );
217
 
                break;
218
 
        case G_Ch_BadHost:
219
 
                KFMsgBox::box( this, QMessageBox::Warning, i18n("Unknown host %1", recvStr() ) );
220
 
                break;
221
 
        case G_Ch_Exit:
222
 
                done( ex_exit );
223
 
                break;
224
 
        default: /* XXX huuh ...? */
225
 
                break;
226
 
        }
 
199
    int cmd = gRecvInt();
 
200
    switch (cmd) {
 
201
    case G_Ch_AddHost:
 
202
    case G_Ch_ChangeHost:
 
203
        id = gRecvInt();
 
204
        nam = recvStr();
 
205
        sts = recvStr();
 
206
        gRecvInt(); /* swallow willing for now */
 
207
        if (cmd == G_Ch_AddHost) {
 
208
            new ChooserListViewItem(host_view, id, nam, sts);
 
209
        } else {
 
210
            QTreeWidgetItem *itm = findItem(id);
 
211
            itm->setText(0, nam);
 
212
            itm->setText(1, sts);
 
213
        }
 
214
        break;
 
215
    case G_Ch_RemoveHost:
 
216
        delete findItem(gRecvInt());
 
217
        break;
 
218
    case G_Ch_BadHost:
 
219
        KFMsgBox::box(this, QMessageBox::Warning, i18n("Unknown host %1", recvStr()));
 
220
        break;
 
221
    case G_Ch_Exit:
 
222
        done(ex_exit);
 
223
        break;
 
224
    default: /* XXX huuh ...? */
 
225
        break;
 
226
    }
227
227
}
228
228
 
229
229
#include "kchooser.moc"