You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.4 KiB
122 lines
3.4 KiB
13 years ago
|
/*! @file
|
||
|
|
||
|
@id $Id$
|
||
|
*/
|
||
|
// 1 2 3 4 5 6 7 8
|
||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||
|
|
||
|
#ifndef __SAVEORRUN_HXX__
|
||
|
#define __SAVEORRUN_HXX__
|
||
|
|
||
|
#include <ui_saveorrun.h>
|
||
|
|
||
|
#include <QtGui/QDialog>
|
||
|
#include <QtGui/QFileDialog>
|
||
|
#include <QtGui/QFileSystemModel>
|
||
|
#include <QtGui/QMessageBox>
|
||
|
#include <memory>
|
||
|
|
||
|
class SaveOrRun: public QDialog, protected Ui::SaveOrRun {
|
||
|
Q_OBJECT;
|
||
|
public:
|
||
|
|
||
|
SaveOrRun(QString obj, QString type, QString src,
|
||
|
bool kiosk=false, QWidget* p=0):
|
||
|
QDialog(p), _ok(false) {
|
||
|
setupUi(this);
|
||
|
_object->setText(obj);
|
||
|
_type->setText(type);
|
||
|
_source->setText(src);
|
||
|
QString path(QDir::homePath());
|
||
|
QStringList defpaths;
|
||
|
defpaths<<"downloads"<<"Downloads"<<"Documents"
|
||
|
<<tr("Dokumente", "Documents folder in local language")
|
||
|
<<"Desktop"
|
||
|
<<tr("Arbeitsfläche", "Desktop folder in local language");
|
||
|
for (auto it(defpaths.begin()); it!=defpaths.end(); ++it)
|
||
|
if (QFile::exists(QDir::homePath()+QDir::separator()+*it)) {
|
||
|
path = QDir::homePath()+QDir::separator()+*it;
|
||
|
break;
|
||
|
}
|
||
|
_filename->setText(path+QDir::separator()+obj);
|
||
|
_program->setText(QCoreApplication::applicationDirPath()
|
||
|
+QDir::separator());
|
||
|
// if (kiosk) {
|
||
|
// _openWith->hide();
|
||
|
// _program->hide();
|
||
|
// _programpath->hide();
|
||
|
// _saveAs->hide();
|
||
|
// _filenamelabel->setText(_saveAs->text()+' '+_filenamelabel->text());
|
||
|
// }
|
||
|
}
|
||
|
|
||
|
void init() {
|
||
|
_ok = false;
|
||
|
}
|
||
|
|
||
|
bool save() {
|
||
|
return _saveAs->isChecked();
|
||
|
}
|
||
|
|
||
|
bool run() {
|
||
|
return _openWith->isChecked();
|
||
|
}
|
||
|
|
||
|
bool ok() {
|
||
|
return _ok;
|
||
|
}
|
||
|
|
||
|
QString filename() {
|
||
|
return _filename->text();
|
||
|
}
|
||
|
|
||
|
QString program() {
|
||
|
return _program->text();
|
||
|
}
|
||
|
|
||
|
public Q_SLOTS:
|
||
|
|
||
|
virtual void accept() {
|
||
|
if (save() && QFileInfo(filename()).exists()
|
||
|
&& QMessageBox::question(this, tr("File Exists"),
|
||
|
tr("File already exists:\n\n"
|
||
|
"%1\n\n"
|
||
|
"Overwrite?").arg(filename()),
|
||
|
QMessageBox::Yes|QMessageBox::No)
|
||
|
== QMessageBox::No
|
||
|
|| run() && (!QFile::exists(program())
|
||
|
|| !QFileInfo(program()).isExecutable())
|
||
|
|| save() && filename().size()==0
|
||
|
|| run() && program().size()==0)
|
||
|
return; // reject
|
||
|
_ok = true;
|
||
|
QDialog::accept();
|
||
|
}
|
||
|
|
||
|
protected Q_SLOTS:
|
||
|
|
||
|
void on__browseSaveAs_clicked(bool) {
|
||
|
QString saveFile
|
||
|
(QFileDialog::getSaveFileName(this, tr("Save File As ..."),
|
||
|
_filename->text(), QString(), 0,
|
||
|
QFileDialog::DontConfirmOverwrite));
|
||
|
if (!saveFile.size()) return;
|
||
|
if (QFileInfo(saveFile).isDir())
|
||
|
saveFile += QDir::separator()+_object->text();
|
||
|
_filename->setText(saveFile);
|
||
|
}
|
||
|
|
||
|
void on__browseOpenWith_clicked(bool) {
|
||
|
QString openFile
|
||
|
(QFileDialog::getOpenFileName(this, tr("Open File With ..."),
|
||
|
_program->text()));
|
||
|
if (openFile.size()) _program->setText(openFile);
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
|
||
|
bool _ok;
|
||
|
};
|
||
|
|
||
|
#endif
|