~x2go/x2go/x2goclient_master

« back to all changes in this revision

Viewing changes to appdialog.cpp

  • Committer: Mihai Moldovan
  • Date: 2015-03-04 20:15:47 UTC
  • Revision ID: git-v1:b7398771a7abd84ddcff407063edb95dd0a205d3
general: move *.cpp and *.h files to src/ and *.ts files to src/i18n/.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**************************************************************************
2
 
*   Copyright (C) 2005-2015 by Oleksandr Shneyder                         *
3
 
*   o.shneyder@phoca-gmbh.de                                              *
4
 
*                                                                         *
5
 
*   This program is free software; you can redistribute it and/or modify  *
6
 
*   it under the terms of the GNU General Public License as published by  *
7
 
*   the Free Software Foundation; either version 2 of the License, or     *
8
 
*   (at your option) any later version.                                   *
9
 
*   This program is distributed in the hope that it will be useful,       *
10
 
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 
*   GNU General Public License for more details.                          *
13
 
*                                                                         *
14
 
*   You should have received a copy of the GNU General Public License     *
15
 
*   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
16
 
***************************************************************************/
17
 
#include "appdialog.h"
18
 
#include "onmainwindow.h"
19
 
 
20
 
AppDialog::AppDialog(ONMainWindow* parent):QDialog(parent)
21
 
{
22
 
    setupUi(this);
23
 
    mw=parent;
24
 
 
25
 
    media=0;
26
 
    dev=0;
27
 
    edu=0;
28
 
    game=0;
29
 
    graph=0;
30
 
    net=0;
31
 
    office=0;
32
 
    set=0;
33
 
    sys=0;
34
 
    util=0;
35
 
    other=0;
36
 
    startButton->setEnabled(false);
37
 
 
38
 
    loadApps();
39
 
}
40
 
 
41
 
AppDialog::~AppDialog()
42
 
{
43
 
 
44
 
}
45
 
 
46
 
void AppDialog::slotSearchChanged(QString text)
47
 
{
48
 
    QTreeWidgetItemIterator it(treeWidget);
49
 
    while (*it)
50
 
    {
51
 
        QString exec=(*it)->data(0,Qt::UserRole).toString();
52
 
        QString comment=(*it)->data(0,Qt::UserRole+1).toString();
53
 
        QString name=(*it)->text(0);
54
 
        if ((*it)->childCount()==0)
55
 
        {
56
 
            if (text.length()<2)
57
 
            {
58
 
                (*it)->setHidden(false);
59
 
                (*it)->setSelected(false);
60
 
            }
61
 
            else
62
 
            {
63
 
                if (exec.indexOf(text, 0,Qt::CaseInsensitive)!= -1 ||
64
 
                        comment.indexOf(text, 0,Qt::CaseInsensitive)!= -1 ||
65
 
                        name.indexOf(text, 0,Qt::CaseInsensitive)!= -1 )
66
 
                {
67
 
                    treeWidget->clearSelection();
68
 
                    (*it)->setSelected(true);
69
 
                    (*it)->setHidden(false);
70
 
                    treeWidget->scrollToItem((*it));
71
 
                }
72
 
                else
73
 
                {
74
 
                    (*it)->setHidden(true);
75
 
                    (*it)->setSelected(false);
76
 
                }
77
 
            }
78
 
        }
79
 
        ++it;
80
 
    }
81
 
}
82
 
 
83
 
QTreeWidgetItem* AppDialog::initTopItem(QString text, QPixmap icon)
84
 
{
85
 
    QTreeWidgetItem* item;
86
 
    item=new QTreeWidgetItem(treeWidget);
87
 
    item->setText(0,text);
88
 
    item->setFlags(Qt::ItemIsEnabled);
89
 
    item->setIcon(0,icon);
90
 
    return item;
91
 
}
92
 
 
93
 
void AppDialog::loadApps()
94
 
{
95
 
    QTreeWidgetItem* parent;
96
 
    foreach (Application app, mw->getApplications())
97
 
    {
98
 
        switch (app.category)
99
 
        {
100
 
        case Application::MULTIMEDIA:
101
 
            if (!media)
102
 
                media=initTopItem(tr("Multimedia"), QPixmap(":/icons/22x22/applications-multimedia.png"));
103
 
            parent=media;
104
 
            break;
105
 
        case Application::DEVELOPMENT:
106
 
            if (!dev)
107
 
                dev=initTopItem(tr("Development"), QPixmap(":/icons/22x22/applications-development.png"));
108
 
            parent=dev;
109
 
            break;
110
 
        case Application::EDUCATION:
111
 
            if (!edu)
112
 
                edu=initTopItem(tr("Education"), QPixmap(":/icons/22x22/applications-education.png"));
113
 
            parent=edu;
114
 
            break;
115
 
        case Application::GAME:
116
 
            if (!game)
117
 
                game=initTopItem(tr("Game"), QPixmap(":/icons/22x22/applications-games.png"));
118
 
            parent=game;
119
 
            break;
120
 
        case Application::GRAPHICS:
121
 
            if (!graph)
122
 
                graph=initTopItem(tr("Graphics"), QPixmap(":/icons/22x22/applications-graphics.png"));
123
 
            parent=graph;
124
 
            break;
125
 
        case Application::NETWORK:
126
 
            if (!net)
127
 
                net=initTopItem(tr("Network"), QPixmap(":/icons/22x22/applications-internet.png"));
128
 
            parent=net;
129
 
            break;
130
 
        case Application::OFFICE:
131
 
            if (!office)
132
 
                office=initTopItem(tr("Office"), QPixmap(":/icons/22x22/applications-office.png"));
133
 
            parent=office;
134
 
            break;
135
 
        case Application::SETTINGS:
136
 
            if (!set)
137
 
                set=initTopItem(tr("Settings"), QPixmap(":/icons/22x22/preferences-system.png"));
138
 
            parent=set;
139
 
            break;
140
 
        case Application::SYSTEM:
141
 
            if (!sys)
142
 
                sys=initTopItem(tr("System"), QPixmap(":/icons/22x22/applications-system.png"));
143
 
            parent=sys;
144
 
            break;
145
 
        case Application::UTILITY:
146
 
            if (!util)
147
 
                util=initTopItem(tr("Utility"), QPixmap(":/icons/22x22/applications-utilities.png"));
148
 
            parent=util;
149
 
            break;
150
 
        case Application::OTHER:
151
 
            if (!other)
152
 
                other=initTopItem(tr("Other"), QPixmap(":/icons/22x22/applications-other.png"));
153
 
            parent=other;
154
 
            break;
155
 
        }
156
 
 
157
 
        QTreeWidgetItem* it;
158
 
        if (app.category==Application::TOP)
159
 
            it=new QTreeWidgetItem(treeWidget);
160
 
        else
161
 
            it=new QTreeWidgetItem(parent);
162
 
        it->setText(0, app.name);
163
 
        it->setToolTip(0,app.comment);
164
 
        it->setIcon(0,app.icon);
165
 
        it->setData(0, Qt::UserRole, app.exec);
166
 
        it->setData(0, Qt::UserRole+1, app.comment);
167
 
    }
168
 
    treeWidget->sortItems(0,Qt::AscendingOrder);
169
 
}
170
 
 
171
 
void AppDialog::slotSelectedChanged()
172
 
{
173
 
    startButton->setEnabled(false);
174
 
    if (treeWidget->selectedItems().count())
175
 
    {
176
 
        startButton->setEnabled(true);
177
 
    }
178
 
}
179
 
 
180
 
void AppDialog::slotDoubleClicked(QTreeWidgetItem* item)
181
 
{
182
 
    QString exec=item->data(0,Qt::UserRole).toString();
183
 
    if (exec.length()>0)
184
 
        mw->runApplication(exec);
185
 
}
186
 
 
187
 
void AppDialog::slotStartSelected()
188
 
{
189
 
    if (treeWidget->selectedItems().count()>0)
190
 
    {
191
 
        QString exec=treeWidget->selectedItems()[0]->data(0,Qt::UserRole).toString();
192
 
        if (exec.length()>0)
193
 
            mw->runApplication(exec);
194
 
    }
195
 
}