1 //=========================================== 2 // Lumina-DE source code 3 // Copyright (c) 2014, Ken Moore 4 // Available under the 3-clause BSD license 5 // See the LICENSE file for full details 6 //=========================================== 7 // This is the dialog for selecting an installed application 8 //=========================================== 9 #ifndef _LUMINA_FILE_MANAGER_APP_SELECT_DIALOG_H 10 #define _LUMINA_FILE_MANAGER_APP_SELECT_DIALOG_H 11 12 #include "globals.h" 13 14 #include "ui_AppDialog.h" 15 16 namespace Ui{ 17 class AppDialog; 18 }; 19 20 class AppDialog : public QDialog{ 21 Q_OBJECT 22 private: 23 Ui::AppDialog *ui; 24 25 public: QDialog(parent)26 AppDialog(QWidget *parent = 0, QString defaultPath = "") : QDialog(parent), ui(new Ui::AppDialog){ 27 ui->setupUi(this); //load the designer file 28 appreset = false; 29 ui->listApps->clear(); 30 QListWidgetItem *defaultItem = 0; 31 QList<XDGDesktop*> APPS = LXDG::sortDesktopNames(APPSLIST->apps(false,false)); //Don't show all/hidden 32 for(int i=0; i<APPS.length(); i++){ 33 QListWidgetItem *app = new QListWidgetItem(LXDG::findIcon(APPS[i]->icon,"application-x-executable"), APPS[i]->name); 34 app->setData(Qt::UserRole, APPS[i]->filePath); 35 ui->listApps->addItem(app); 36 if(APPS[i]->filePath == defaultPath){ 37 defaultItem = app; 38 } 39 } 40 if(ui->listApps->count()){ 41 ui->listApps->setCurrentItem(defaultItem != 0 ? defaultItem : ui->listApps->item(0)); 42 } 43 this->setWindowIcon( LXDG::findIcon("system-search","") ); 44 if(parent!=0){ 45 QWidget *top = parent; 46 while(!top->isWindow()){ top = top->parentWidget(); } 47 QPoint center = top->geometry().center(); 48 this->move(center.x()-(this->width()/2), center.y()-(this->height()/2) ); 49 } 50 } 51 ~AppDialog()52 ~AppDialog(){} 53 allowReset(bool allow)54 void allowReset(bool allow){ 55 if(allow){ 56 ui->buttonBox->setStandardButtons(QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 57 }else{ 58 ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 59 } 60 } 61 62 QString appselected; //selected application 63 bool appreset; //Did the user select to reset to defaults? 64 65 66 private slots: on_buttonBox_accepted()67 void on_buttonBox_accepted(){ 68 QListWidgetItem *item = ui->listApps->currentItem(); 69 if(item != 0){ 70 appselected = item->data(Qt::UserRole).toString(); 71 } 72 this->close(); 73 } on_buttonBox_rejected()74 void on_buttonBox_rejected(){ 75 this->close(); 76 } on_buttonBox_clicked(QAbstractButton * button)77 void on_buttonBox_clicked(QAbstractButton *button){ 78 if(ui->buttonBox->standardButton(button) == QDialogButtonBox::RestoreDefaults){ 79 appreset = true; 80 this->close(); 81 } 82 } on_listApps_itemDoubleClicked(QListWidgetItem * item)83 void on_listApps_itemDoubleClicked(QListWidgetItem *item){ 84 appselected = item->data(Qt::UserRole).toString(); 85 this->close(); 86 } on_lineSearch_textChanged(const QString & term)87 void on_lineSearch_textChanged(const QString &term){ 88 QListWidgetItem *first_visible = 0; 89 for(int i = 0; i < ui->listApps->count(); i++){ 90 QListWidgetItem *item = ui->listApps->item(i); 91 bool visible = item->text().contains(term, Qt::CaseInsensitive); 92 item->setHidden(!visible); 93 if(visible && first_visible == 0){ 94 first_visible = item; 95 } 96 } 97 //Select the first app 98 ui->listApps->setCurrentItem(first_visible); 99 if(first_visible != 0){ 100 ui->listApps->scrollToItem(first_visible); 101 } 102 } 103 }; 104 105 #endif 106