blob: 2b03fc76995570face2f560827b07ef30f539df8 (
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
|
//===========================================
// Lumina-DE source code
// Copyright (c) 2014, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
// This is the dialog for selecting an installed application
//===========================================
#ifndef _LUMINA_FILE_MANAGER_APP_SELECT_DIALOG_H
#define _LUMINA_FILE_MANAGER_APP_SELECT_DIALOG_H
#include "globals.h"
#include "ui_AppDialog.h"
namespace Ui{
class AppDialog;
};
class AppDialog : public QDialog{
Q_OBJECT
private:
Ui::AppDialog *ui;
public:
AppDialog(QWidget *parent = 0, QString defaultPath = "") : QDialog(parent), ui(new Ui::AppDialog){
ui->setupUi(this); //load the designer file
appreset = false;
ui->listApps->clear();
QListWidgetItem *defaultItem = nullptr;
QList<XDGDesktop*> APPS = LXDG::sortDesktopNames(APPSLIST->apps(false,false)); //Don't show all/hidden
for(int i=0; i<APPS.length(); i++){
QListWidgetItem *app = new QListWidgetItem(LXDG::findIcon(APPS[i]->icon,"application-x-executable"), APPS[i]->name);
app->setData(Qt::UserRole, APPS[i]->filePath);
ui->listApps->addItem(app);
if(APPS[i]->filePath == defaultPath){
defaultItem = app;
}
}
if(ui->listApps->count()){
ui->listApps->setCurrentItem(defaultItem != nullptr ? defaultItem : ui->listApps->item(0));
}
this->setWindowIcon( LXDG::findIcon("system-search","") );
if(parent!=0){
QWidget *top = parent;
while(!top->isWindow()){ top = top->parentWidget(); }
QPoint center = top->geometry().center();
this->move(center.x()-(this->width()/2), center.y()-(this->height()/2) );
}
}
~AppDialog(){}
void allowReset(bool allow){
if(allow){
ui->buttonBox->setStandardButtons(QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
}else{
ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
}
}
QString appselected; //selected application
bool appreset; //Did the user select to reset to defaults?
private slots:
void on_buttonBox_accepted(){
QListWidgetItem *item = ui->listApps->currentItem();
if(item != nullptr){
appselected = item->data(Qt::UserRole).toString();
}
this->close();
}
void on_buttonBox_rejected(){
this->close();
}
void on_buttonBox_clicked(QAbstractButton *button){
if(ui->buttonBox->standardButton(button) == QDialogButtonBox::RestoreDefaults){
appreset = true;
this->close();
}
}
void on_listApps_itemDoubleClicked(QListWidgetItem *item){
appselected = item->data(Qt::UserRole).toString();
this->close();
}
void on_lineSearch_textChanged(const QString &term){
QListWidgetItem *first_visible = nullptr;
for(int i = 0; i < ui->listApps->count(); i++){
QListWidgetItem *item = ui->listApps->item(i);
bool visible = item->text().contains(term, Qt::CaseInsensitive);
item->setHidden(!visible);
if(visible && first_visible == nullptr){
first_visible = item;
}
}
//Select the first app
ui->listApps->setCurrentItem(first_visible);
if(first_visible != nullptr){
ui->listApps->scrollToItem(first_visible);
}
}
};
#endif
|