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 #include "ScriptDialog.h"
8 #include "ui_ScriptDialog.h"
9 
10 //===========
11 //    PUBLIC
12 //===========
ScriptDialog(QWidget * parent)13 ScriptDialog::ScriptDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ScriptDialog){
14   ui->setupUi(this);
15   ok = false;
16   connect(ui->line_name, SIGNAL(textEdited(QString)), this, SLOT(checkItems()) );
17   connect(ui->line_exec, SIGNAL(textEdited(QString)), this, SLOT(checkItems()) );
18   connect(ui->line_icon, SIGNAL(textEdited(QString)), this, SLOT(checkItems()) );
19   checkItems(true);
20 }
21 
~ScriptDialog()22 ScriptDialog::~ScriptDialog(){
23 
24 }
25 
26 //Main interaction functions
isValid()27 bool ScriptDialog::isValid(){
28   return ok;
29 }
30 
icon()31 QString ScriptDialog::icon(){
32   return ui->line_icon->text();
33 }
34 
name()35 QString ScriptDialog::name(){
36   return ui->line_name->text();
37 }
38 
command()39 QString ScriptDialog::command(){
40   return ui->line_exec->text();
41 }
42 
43 //==============
44 // PRIVATE SLOTS
45 //==============
on_pushApply_clicked()46 void ScriptDialog::on_pushApply_clicked(){
47   ok = true;
48   this->close();
49 }
50 
on_pushCancel_clicked()51 void ScriptDialog::on_pushCancel_clicked(){
52  ok = false;
53   this->close();
54 }
55 
on_tool_getexec_clicked()56 void ScriptDialog::on_tool_getexec_clicked(){
57   QString file = QFileDialog::getOpenFileName( this, tr("Select a menu script"), LOS::LuminaShare()+"/menu-scripts/" );
58   if(file.isEmpty()){ return; } //cancelled
59   ui->line_exec->setText(file);
60   checkItems();
61 }
62 
on_tool_geticon_clicked()63 void ScriptDialog::on_tool_geticon_clicked(){
64   QString file = QFileDialog::getOpenFileName( this, tr("Select an icon file"), QDir::homePath() );
65   if(file.isEmpty()){ return; } //cancelled
66   ui->line_icon->setText(file);
67   checkItems();
68 }
69 
checkItems(bool firstrun)70 void ScriptDialog::checkItems(bool firstrun){
71   if(firstrun){
72     ui->line_name->setFocus();
73     ui->label_sample->setPixmap( LXDG::findIcon("text-x-script","").pixmap(32,32) );
74     ui->tool_geticon->setIcon( LXDG::findIcon("system-search","") );
75     ui->tool_getexec->setIcon( LXDG::findIcon("system-search","") );
76   }
77   //Update the icon sample if needed
78   if(icon()!=ui->label_sample->whatsThis()){
79     ui->label_sample->setPixmap( LXDG::findIcon(icon(),"text-x-script").pixmap(32,32) );
80     ui->label_sample->setWhatsThis(icon());
81   }
82   bool good = true;
83   if(name().isEmpty()){ good = false; ui->line_name->setStyleSheet("color: red;"); }
84   else{ ui->line_name->setStyleSheet(""); }
85   QString cmd = command().section(" ",0,0).simplified();
86   if( cmd.isEmpty() || !LUtils::isValidBinary(cmd) ){ good = false; ui->line_exec->setStyleSheet("color: red;"); }
87   else{ ui->line_exec->setStyleSheet(""); }
88 
89   ui->pushApply->setEnabled(good);
90 }
91