Feature: user can set commands fo opening shared files with some external applications. First revision. TODO: test on Windows, add additional functionality(see trac)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1119 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
beardog_uk 2009-04-07 08:08:03 +00:00
parent ab43d876c8
commit 22c2974466
13 changed files with 1171 additions and 226 deletions

View file

@ -0,0 +1,228 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2009 The RetroShare Team, Oleksiy Bilyanskyy
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "AddFileAssotiationDialog.h"
//#include "rshare.h" // for Rshare::dataDirectory() method
//#include "rsharesettings.h"
#include <QSettings> //for win registry access
#include <QApplication>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QSizePolicy>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QDebug>
//============================================================================
AddFileAssotiationDialog::AddFileAssotiationDialog(bool onlyEdit,
QWidget* parent)
:QDialog(parent)
{
fileTypeLabel = new QLabel();
fileTypeLabel->setText(tr("File type(extension):"));
fileTypeEdit = new QLineEdit();
fileTypeEdit->setEnabled( !onlyEdit );
fileTypeEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
fileTypeEdit->setFixedWidth(50);
connect(fileTypeEdit, SIGNAL( textEdited( const QString& )),
this , SLOT( fileTypeEdited(const QString & )) ) ;
loadSystemDefault = new QPushButton();
loadSystemDefault->setText(tr("Use default command"));
loadSystemDefault->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
loadSystemDefault->setEnabled( fileTypeEdit &&
(!(fileTypeEdit->text().isEmpty())) ) ;
connect(loadSystemDefault, SIGNAL(clicked()),
this, SLOT(loadSystemDefaultCommand()));
loadSystemDefault->setVisible(false); //the button sholud remain unvisivle,
//until it will work properly
commandLabel = new QLabel();
commandLabel->setText(tr("Command"));
commandEdit = new QLineEdit;
selectExecutable = new QPushButton();
selectExecutable->setText("...");
selectExecutable->setFixedWidth(30);
QHBoxLayout* ftlay = new QHBoxLayout();
ftlay->addWidget( fileTypeLabel );
ftlay->addWidget( fileTypeEdit );
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel );
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QGridLayout* mainLay = new QGridLayout();
mainLay->addWidget(fileTypeLabel,0,0,1,1, Qt::AlignLeft);
mainLay->addWidget(fileTypeEdit,0,1,1,1, Qt::AlignLeft);
mainLay->addWidget(loadSystemDefault, 0,2,1,2,Qt::AlignRight);
mainLay->addWidget( commandLabel, 1,0,1,1, Qt::AlignLeft);
mainLay->addWidget( commandEdit, 1,1,1,2);
mainLay->addWidget( selectExecutable, 1,3,1,1);
mainLay->addWidget( buttonBox, 2,1,1,4, Qt::AlignLeft);
mainLay->setColumnStretch(2,1);
mainLay->setRowStretch(2,1);
this->setLayout( mainLay );
//TODO: in the next line we have to count a real height of the dialog;
// It's not good to use a hardcoded const value;
this->resize(600,200);//this->height());
}
//============================================================================
void
AddFileAssotiationDialog::fileTypeEdited(const QString & text )
{
loadSystemDefault->setEnabled( !( text.isEmpty() ) );
}
//============================================================================
void
AddFileAssotiationDialog::setFileType(QString ft)
{
fileTypeEdit->setText(ft);
}
//============================================================================
void
AddFileAssotiationDialog::loadSystemDefaultCommand()
{
qDebug() << " lsdc is here";
QString fileExt = cleanFileType(fileTypeEdit->text()) ;
//fileExt.prepend('/');
fileExt.append("/.");
qDebug() << " fileExt is " << fileExt;
QSettings reg("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
if (reg.contains(fileExt))
{
QString appKey = reg.value(fileExt).toString();
qDebug() << " got app key " << appKey;
appKey.append("/shell/open/command/.");
QString command = reg.value(appKey, "-").toString();
if (command!="-")
{
qDebug() << " got command :" << command ;
commandEdit->setText( command );
return;
}
}
QMessageBox::warning(this, tr("RetroShare"),
tr("Sorry, can't determine system "
"default command for this file\n"),
QMessageBox::Ok);
}
//============================================================================
QString
AddFileAssotiationDialog::cleanFileType(QString ft)
{
QString result = ft;
//-- first remove possible filder names from received filename. (like
// "like "/moviedir/file.avi", we will leave only "file.avi"
int ti;
// dirs may be separated with "/"
ti = result.lastIndexOf('/');
if (ti > -1)
{
result.remove(0,ti+1);
}
// or "\"
ti = result.lastIndexOf('\\');
if (ti > -1)
{
result.remove(0,ti+1);
}
//-- then, if it is filename (like "file.avi"), we'll have to remove
//-- the name (ans leave just ".avi")
ti = result.lastIndexOf('.');
if (ti > -1)
{
result.remove(0,ti);
return result;
}
//-- also, if filename still is not prepended with dot, do it
if ( (result.at(0)!='.')&&(! result.isEmpty()) )
result.prepend('.');
//-- that's all
return result;
}
//============================================================================
QString
AddFileAssotiationDialog::resultCommand()
{
return commandEdit->text();
}
//============================================================================
QString
AddFileAssotiationDialog::resultFileType()
{
return cleanFileType( fileTypeEdit->text() ) ;
}
//============================================================================
void
AddFileAssotiationDialog::setCommand(QString cmd)
{
commandEdit->setText( cmd );
}
//============================================================================
//============================================================================

View file

@ -0,0 +1,80 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2009 The RetroShare Team, Oleksiy Bilyanskyy
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef __AddFileAssotiationDialog__
#define __AddFileAssotiationDialog__
#include <QString>
#include <QDialog>
class QPushButton;
class QDialogButtonBox;
class QLabel;
class QLineEdit;
//=============================================================================
//! A dialog for specifying file type and associated command
class AddFileAssotiationDialog: public QDialog
{
Q_OBJECT
public:
//! constructor
//! if (onlyEdit == true), user woll not be able to change file type,
//! only command (used for editing existing commands)
AddFileAssotiationDialog( bool onlyEdit = false, QWidget *parent = 0 ) ;
virtual ~AddFileAssotiationDialog(){};
void setFileType(QString ft);
void setCommand(QString cmd);
//! Gets file type (file extension) from given filename (or other string)
//! "file type" has to be like '.png'(some symbols, prepended by a dot)
static QString cleanFileType(QString ft);
QString resultCommand();
QString resultFileType();
protected:
//QTabWidget *tabWidget;
QLabel* fileTypeLabel;
QLineEdit* fileTypeEdit;
QPushButton* loadSystemDefault;
QPushButton* selectExecutable;
QLabel* commandLabel;
QLineEdit* commandEdit;
QDialogButtonBox *buttonBox;
protected slots:
void fileTypeEdited(const QString & text );
//! On win32, loads default command from system registry.
//! Unfinished. Is not used in current version.
void loadSystemDefaultCommand();
};
#endif

View file

@ -0,0 +1,379 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2009 The RetroShare Team, Oleksiy Bilyanskyy
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "FileAssotiationsDialog.h"
#include "AddFileAssotiationDialog.h"
//#include "rshare.h" // for Rshare::dataDirectory() method
#include "rsharesettings.h"
#include <QSettings>
#include <QApplication>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QSizePolicy>
//#include <QLabel>
//#include <QLineEdit>
#include <QToolBar>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QStringList>
#include <QAction>
#include <QMessageBox>
#include <QProcess>
#include <QDebug>
#include <QMessageBox>
//#include <iostream>
//============================================================================
FileAssotiationsDialog::FileAssotiationsDialog(QWidget* parent)
:ConfigPage(parent)
//:QFrame()
{
QVBoxLayout* pageLay = new QVBoxLayout(this);
toolBar = new QToolBar("actions", this);
newAction = new QAction(QIcon(":/images/add_24x24.png"), tr("&New"), this);
//newAction->setShortcut(tr("Ctrl+N"));
newAction->setStatusTip(tr("Add new assotiation"));
connect(newAction, SIGNAL(triggered()), this, SLOT(addnew()));
toolBar->addAction(newAction);
editAction = new QAction(QIcon(":/images/kcmsystem24.png"),
tr("&Edit"), this);
editAction->setStatusTip(tr("Edit this assotiation"));
connect(editAction, SIGNAL(triggered()), this, SLOT(edit()));
toolBar->addAction(editAction);
removeAction = new QAction(QIcon(":/images/edit_remove24.png"),
tr("&Remove"), this);
removeAction->setStatusTip(tr("Remove this assotiation"));
connect(removeAction, SIGNAL(triggered()), this, SLOT(remove()));
toolBar->addAction( removeAction );
pageLay->addWidget( toolBar );
table = new QTableWidget(5,2,this);//default 5 rows, 2 columns
table->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("File type") ) );
table->setHorizontalHeaderItem(1, new QTableWidgetItem("Command") );
connect( table, SIGNAL( cellActivated(int, int)),
this, SLOT( tableCellActivated(int, int)) );
connect( table, SIGNAL( cellClicked(int, int)),
this, SLOT( tableCellActivated(int, int)) );
// connect( table, SIGNAL( cellChanged(int, int)),
// this, SLOT( tableCellActivated(int, int)) );
//
// connect( table, SIGNAL( cellDoubleClicked(int, int)),
// this, SLOT( tableCellActivated(int, int)) );
//
// connect( table, SIGNAL( cellEntered(int, int)),
// this, SLOT( tableCellActivated(int, int)) );
//
// connect( table, SIGNAL( cellPressed(int, int)),
// this, SLOT( tableCellActivated(int, int)) );
// connect( table, SIGNAL( itemClicked(QTableWidgetItem*)),
// this, SLOT( tableItemActivated(QTableWidgetItem*)) );
pageLay->addWidget(table);
// addNewAssotiationButton = new QPushButton;
// addNewAssotiationButton->setText(tr("Add.."));
// QHBoxLayout* anbLay = new QHBoxLayout;
// anbLay->addStretch();
// anbLay->addWidget(addNewAssotiationButton);
// pageLay->addLayout(anbLay);
// connect( addNewAssotiationButton, SIGNAL( clicked() ),
// this, SLOT( testButtonClicked() ) );
settings = new RshareSettings();
//new QSettings( qApp->applicationDirPath()+"/sett.ini",
// QSettings::IniFormat);
settings->beginGroup("FileAssotiations");
}
//============================================================================
FileAssotiationsDialog::~FileAssotiationsDialog()
{
delete settings ;
}
//============================================================================
bool
FileAssotiationsDialog::save (QString &errmsg)
{
//RshareSettings* settings = new RshareSettings();
// settings->beginGroup("FileAssotiations");
// settings->setValue(".s01", "s01 test");
// settings->setValue(".s02", "s02 test");
// settings->setValue(".s03", "s03 test");
// settings->setValue(".s04", "s04 test");
// QMap<QString, QString>::const_iterator ati = ations.constBegin();
// while (ati != ations.constEnd())
// {
// settings->setValue( ati.key(), ati.value() );
// qDebug() << " - " << ati.key() << ati.value() << "\n" ;
// ati++;
// }
//
// settings->endGroup();
settings->sync();
// delete settings;
/* */
return true;
}
//============================================================================
void
FileAssotiationsDialog::load()
{
//RshareSettings* settings = new RshareSettings();
// QSettings* settings = new QSettings( qApp->applicationDirPath()+"/sett.ini",
// QSettings::IniFormat);
//
// settings->beginGroup("FileAssotiations");
QStringList keys = settings->allKeys();
table->setRowCount( keys.count() );
int rowi = 0;
QStringList::const_iterator ki;
for(ki=keys.constBegin(); ki!=keys.constEnd(); ki++)
{
QString val = (settings->value(*ki, "")).toString();
addNewItemToTable( rowi, 0, *ki );
addNewItemToTable( rowi, 1, val );
rowi++;
}
//delete settings;
if (keys.count()==0)
{
removeAction->setEnabled(false);
editAction->setEnabled(false);
}
table->selectRow(0);
}
//============================================================================
void
FileAssotiationsDialog::remove()
{
int currentRow = table->currentRow() ;
QTableWidgetItem const * titem = table->item( currentRow,0);
QString key = (titem->data(QTableWidgetItem::Type)).toString();
settings->remove(key);
table->removeRow( currentRow );
if ( table->rowCount()==0 )
{
removeAction->setEnabled(false);
editAction->setEnabled(false);
}
}
//============================================================================
void
FileAssotiationsDialog::addnew()
{
AddFileAssotiationDialog afad(false, this);//'add file assotiations' dialog
int currentRow = table->currentRow() ;
QTableWidgetItem* titem;
int ti = afad.exec();
if (ti==QDialog::Accepted)
{
QString currType = afad.resultFileType() ;
QString currCmd = afad.resultCommand() ;
if ( !settings->contains(currType) )//new item should be added only if
{ // it wasn't entered before.
int nridx = table->rowCount();//new row index
table->setRowCount(nridx+1);
addNewItemToTable(nridx,0, currType) ;
addNewItemToTable(nridx,1, currCmd);
}
else
{
for(int rowi=0; rowi<table->rowCount(); rowi++)
{
titem = table->item( rowi, 0);
if (titem->data(QTableWidgetItem::Type).toString()==currType)
{
titem = table->item( rowi, 1);
titem->setData(QTableWidgetItem::Type, currCmd);
break;
}
}
}
settings->setValue(currType, currCmd);
removeAction->setEnabled(true);
editAction->setEnabled(true);
}
}
//============================================================================
void
FileAssotiationsDialog::edit()
{
AddFileAssotiationDialog afad(true, this);//'add file assotiations' dialog
int currentRow = table->currentRow() ;
QTableWidgetItem* titem;
titem = table->item( currentRow,0);
QString currType = (titem->data(QTableWidgetItem::Type)).toString();
titem = table->item( currentRow,1);
QString currCmd = (titem->data(QTableWidgetItem::Type)).toString();
afad.setCommand(currCmd);
afad.setFileType(currType);
int ti = afad.exec();
if (ti==QDialog::Accepted)
{
currCmd = afad.resultCommand() ;
titem = table->item( currentRow,1);
titem->setData(QTableWidgetItem::Type, currCmd);
settings->setValue(currType, currCmd);
}
}
//============================================================================
void
FileAssotiationsDialog::tableCellActivated ( int row, int column )
{
table->selectRow(row);
}
//============================================================================
void
FileAssotiationsDialog::tableItemActivated ( QTableWidgetItem * item )
{
qDebug() << "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n";
QMessageBox::information(this,
tr(" Friend Help"),
tr("You this"));
table->selectRow(table->row(item));
}
//============================================================================
void
FileAssotiationsDialog::addNewItemToTable(int row, int column,
QString itemText)
{
QTableWidgetItem* tmpitem ;
tmpitem = new QTableWidgetItem(itemText) ;
tmpitem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
// | Qt::ItemIsUserCheckable);
table->setItem(row, column, tmpitem );
}
//============================================================================
void
FileAssotiationsDialog::testButtonClicked()
{
AddFileAssotiationDialog afad(this);// = new AddFileAssotiationDialog();
// commented code below is a test for
// AddFileAssotiationDialog::loadSystemDefaultCommand(QString ft) method
// QString tmps;
// tmps = "/home/folder/file";
// qDebug() << " for " << tmps <<" is " << afad.cleanFileType(tmps);
// tmps = "/home/folder/file.avi";
// qDebug() << " for " << tmps <<" is " << afad.cleanFileType(tmps);
// tmps = "file.avi";
// qDebug() << " for " << tmps <<" is " << afad.cleanFileType(tmps);
// tmps = ".file";
// qDebug() << " for " << tmps <<" is " << afad.cleanFileType(tmps);
// tmps = "c:\\home\\folder\\file";
// qDebug() << " for " << tmps <<" is " << afad.cleanFileType(tmps);
// tmps = "/home/folder/.file";
// qDebug() << " for " << tmps <<" is " << afad.cleanFileType(tmps);
// tmps = "D:\\folder\\file.asd.avi";
// qDebug() << " for " << tmps <<" is " << afad.cleanFileType(tmps);
int ti = afad.exec();
if (ti==QDialog::Accepted)
{
qDebug() << " dialog was accepted";
QProcess::execute(afad.resultCommand());//,
//QStringList("D:\\prog\\eclipse_workspace\\tapp-fa\\tt.txt") );
qDebug() << " process finished?";
}
else
if (ti == QDialog::Rejected)
qDebug() << " dialog rejected" ;
else
qDebug() << "dialog returned something else" ;
}
//============================================================================

View file

@ -0,0 +1,90 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2009 The RetroShare Team, Oleksiy Bilyanskyy
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef __FileAssotiationsDialog__
#define __FileAssotiationsDialog__
#include "configpage.h"
#include <QString>
//#include <QMap>
//#include <QFrame>
//#include <QDialog>
class QToolBar;
class QAction;
class QTableWidget;
class QTableWidgetItem;
class QPushButton;
class QDialogButtonBox;
class QLabel;
class QLineEdit;
//class QSettings;
class RshareSettings;
//=============================================================================
//! Dialog for setting file assotiations for RS
//! With this config page user can specify, what programs should be executed
//! to open some types of files. Here 'type' means 'file extension'(and
//! 'file extension' means 'some symbols after last dot in filename').
class FileAssotiationsDialog : public ConfigPage
{
Q_OBJECT
public:
FileAssotiationsDialog(QWidget* parent = 0);
virtual ~FileAssotiationsDialog();
void load();
bool save (QString &errmsg);
protected:
QToolBar* toolBar;
QAction* newAction;
QAction* editAction;
QAction* removeAction;
QTableWidget* table;
QPushButton* addNewAssotiationButton;
QString settingsFileName;
RshareSettings* settings;
// QSettings* settings;
void addNewItemToTable(int row, int column, QString itemText);
protected slots:
void remove();
void addnew();
void edit();
void tableCellActivated ( int row, int column );
void tableItemActivated ( QTableWidgetItem * item ) ;
void testButtonClicked();//! slot for debuggin purposes, nnot really used
};
#endif

View file

@ -17,71 +17,79 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QMessageBox>
#include <rshare.h>
#include "PreferencesWindow.h"
****************************************************************/
#include <QMessageBox>
#include <rshare.h>
#include "PreferencesWindow.h"
#include "rsiface/rsiface.h"
#define FONT QFont(tr("Arial"), 8)
/* Images for toolbar icons */
#define IMAGE_PREFERENCES ":/images/kcmsystem24.png"
#define IMAGE_SERVER ":/images/server_24x24.png"
#define IMAGE_DIRECTORIES ":/images/folder_doments.png"
#define IMAGE_CRYPTOGRAPHY ":/images/cryptography_24x24.png"
#define IMAGE_LOG ":/images/log_24x24.png"
#define IMAGE_ABOUT ":/images/informations_24x24.png"
#define IMAGE_SAVE ":/images/media-floppy.png"
#define FONT QFont(tr("Arial"), 8)
/* Images for toolbar icons */
#define IMAGE_PREFERENCES ":/images/kcmsystem24.png"
#define IMAGE_SERVER ":/images/server_24x24.png"
#define IMAGE_DIRECTORIES ":/images/folder_doments.png"
#define IMAGE_CRYPTOGRAPHY ":/images/cryptography_24x24.png"
#define IMAGE_LOG ":/images/log_24x24.png"
#define IMAGE_ABOUT ":/images/informations_24x24.png"
#define IMAGE_SAVE ":/images/media-floppy.png"
#define IMAGE_HELP ":/images/help24.png"
#define IMAGE_APPEARRANCE ":/images/looknfeel.png"
/** Constructor */
PreferencesWindow::PreferencesWindow(QWidget *parent, Qt::WFlags flags)
: RWindow("PreferencesWindow", parent, flags)
{
/* Invoke the Qt Designer generated QObject setup routine */
ui.setupUi(this);
/* Create the config pages and actions */
QActionGroup *grp = new QActionGroup(this);
ui.stackPages->add(new GeneralDialog(ui.stackPages),
#define IMAGE_APPEARRANCE ":/images/looknfeel.png"
#define IMAGE_FILE_ASSOTIATIONS ":/images/folder-draft24.png"
/** Constructor */
PreferencesWindow::PreferencesWindow(QWidget *parent, Qt::WFlags flags)
: RWindow("PreferencesWindow", parent, flags)
{
/* Invoke the Qt Designer generated QObject setup routine */
ui.setupUi(this);
/* Create the config pages and actions */
QActionGroup *grp = new QActionGroup(this);
ui.stackPages->add(new GeneralDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_PREFERENCES), tr("General"), grp));
ui.stackPages->add(new ServerDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_SERVER), tr("Server"), grp));
ui.stackPages->add(new DirectoriesDialog(ui.stackPages),
ui.stackPages->add(new ServerDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_SERVER), tr("Server"), grp));
ui.stackPages->add(new DirectoriesDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_DIRECTORIES), tr("Directories"), grp));
ui.stackPages->add(new AppearanceDialog(ui.stackPages),
ui.stackPages->add(new AppearanceDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_APPEARRANCE), tr("Appearance"), grp));
ui.stackPages->add(new NotifyDialog(ui.stackPages),
ui.stackPages->add(new NotifyDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_APPEARRANCE), tr("Notify"), grp));
ui.stackPages->add(new FileAssotiationsDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_FILE_ASSOTIATIONS),
tr("File assotiations"), grp));
/*foreach (ConfigPage *page, ui.stackPages->pages()) {
connect(page, SIGNAL(helpRequested(QString)),
this, SLOT(help(QString)));
} */
/* Create the toolbar */
ui.toolBar->addActions(grp->actions());
ui.toolBar->addSeparator();
connect(grp, SIGNAL(triggered(QAction *)), ui.stackPages, SLOT(showPage(QAction *)));
} */
/* Create the toolbar */
ui.toolBar->addActions(grp->actions());
ui.toolBar->addSeparator();
connect(grp, SIGNAL(triggered(QAction *)), ui.stackPages, SLOT(showPage(QAction *)));
/* Create and bind the Help button */
QAction *helpAct = new QAction(QIcon(IMAGE_HELP), tr("Help"), ui.toolBar);
addAction(helpAct, SLOT(showHelp()));
/* Select the first action */
grp->actions()[0]->setChecked(true);
addAction(helpAct, SLOT(showHelp()));
/* Select the first action */
grp->actions()[0]->setChecked(true);
// setFixedSize(QSize(480, 450));
connect(ui.okButton, SIGNAL(clicked( bool )), this, SLOT( saveChanges()) );
@ -92,103 +100,103 @@ PreferencesWindow::PreferencesWindow(QWidget *parent, Qt::WFlags flags)
#else
helpAct->setShortcut(QString("Ctrl+?"));
#endif
}
/** Creates a new action associated with a config page. */
QAction*
PreferencesWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
{
QAction *action = new QAction(img, text, group);
action->setCheckable(true);
action->setFont(FONT);
return action;
}
/** Adds the given action to the toolbar and hooks its triggered() signal to
* the specified slot (if given). */
void
PreferencesWindow::addAction(QAction *action, const char *slot)
{
action->setFont(FONT);
ui.toolBar->addAction(action);
connect(action, SIGNAL(triggered()), this, slot);
}
/** Overloads the default show so we can load settings */
/*void
PreferencesWindow::show()
{*/
/* Load saved settings */
/*loadSettings();
if (!this->isVisible()) {
QMainWindow::show();
} else {
QMainWindow::activateWindow();
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
QMainWindow::raise();
}
}*/
/** Shows the Preferences dialog with focus set to the given page. */
void
PreferencesWindow::showWindow(Page page)
{
/* Load saved settings */
loadSettings();
/* Show the dialog. */
RWindow::showWindow();
/* Set the focus to the specified page. */
ui.stackPages->setCurrentIndex((int)page);
}
/** Loads the saved PreferencesWindow settings. */
void
PreferencesWindow::loadSettings()
{
/* Call each config page's load() method to load its data */
foreach (ConfigPage *page, ui.stackPages->pages()) {
page->load();
}
}
/** Saves changes made to settings. */
void
PreferencesWindow::saveChanges()
{
QString errmsg;
/* Call each config page's save() method to save its data */
foreach (ConfigPage *page, ui.stackPages->pages()) {
if (!page->save(errmsg)) {
/* Display the offending page */
ui.stackPages->setCurrentPage(page);
/* Show the user what went wrong */
QMessageBox::warning(this,
tr("Error Saving Configuration"), errmsg,
QMessageBox::Ok, QMessageBox::NoButton);
/* Don't process the rest of the pages */
return;
}
}
/** Creates a new action associated with a config page. */
QAction*
PreferencesWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
{
QAction *action = new QAction(img, text, group);
action->setCheckable(true);
action->setFont(FONT);
return action;
}
/** Adds the given action to the toolbar and hooks its triggered() signal to
* the specified slot (if given). */
void
PreferencesWindow::addAction(QAction *action, const char *slot)
{
action->setFont(FONT);
ui.toolBar->addAction(action);
connect(action, SIGNAL(triggered()), this, slot);
}
/** Overloads the default show so we can load settings */
/*void
PreferencesWindow::show()
{*/
/* Load saved settings */
/*loadSettings();
if (!this->isVisible()) {
QMainWindow::show();
} else {
QMainWindow::activateWindow();
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
QMainWindow::raise();
}
}*/
/** Shows the Preferences dialog with focus set to the given page. */
void
PreferencesWindow::showWindow(Page page)
{
/* Load saved settings */
loadSettings();
/* Show the dialog. */
RWindow::showWindow();
/* Set the focus to the specified page. */
ui.stackPages->setCurrentIndex((int)page);
}
/** Loads the saved PreferencesWindow settings. */
void
PreferencesWindow::loadSettings()
{
/* Call each config page's load() method to load its data */
foreach (ConfigPage *page, ui.stackPages->pages()) {
page->load();
}
}
/** Saves changes made to settings. */
void
PreferencesWindow::saveChanges()
{
QString errmsg;
/* Call each config page's save() method to save its data */
foreach (ConfigPage *page, ui.stackPages->pages()) {
if (!page->save(errmsg)) {
/* Display the offending page */
ui.stackPages->setCurrentPage(page);
/* Show the user what went wrong */
QMessageBox::warning(this,
tr("Error Saving Configuration"), errmsg,
QMessageBox::Ok, QMessageBox::NoButton);
/* Don't process the rest of the pages */
return;
}
}
/* call to RsIface save function.... */
//rsicontrol -> ConfigSave();
QMainWindow::close();
QMainWindow::close();
}
/** Cancel and close the Preferences Window. */
void
PreferencesWindow::cancelpreferences()
{
QMainWindow::close();
/** Cancel and close the Preferences Window. */
void
PreferencesWindow::cancelpreferences()
{
QMainWindow::close();
}
void
@ -245,5 +253,5 @@ PreferencesWindow::help(const QString &topic)
emit helpRequested(topic);
}*/

View file

@ -17,59 +17,60 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _PreferencesWindow_H
#define _PreferencesWindow_H
#include <QMainWindow>
#include <QFileDialog>
#include "GeneralDialog.h"
#include "DirectoriesDialog.h"
#include "ServerDialog.h"
#include "CryptographyDialog.h"
****************************************************************/
#ifndef _PreferencesWindow_H
#define _PreferencesWindow_H
#include <QMainWindow>
#include <QFileDialog>
#include "GeneralDialog.h"
#include "DirectoriesDialog.h"
#include "ServerDialog.h"
#include "CryptographyDialog.h"
#include "AppearanceDialog.h"
#include "NotifyDialog.h"
#include "gui/help/browser/helpbrowser.h"
#include <gui/common/rwindow.h>
#include "ui_PreferencesWindow.h"
class PreferencesWindow : public RWindow
{
Q_OBJECT
public:
/** Preferences dialog pages. */
enum Page {
General = 0, /** Preferences page. */
#include "FileAssotiationsDialog.h"
#include "gui/help/browser/helpbrowser.h"
#include <gui/common/rwindow.h>
#include "ui_PreferencesWindow.h"
class PreferencesWindow : public RWindow
{
Q_OBJECT
public:
/** Preferences dialog pages. */
enum Page {
General = 0, /** Preferences page. */
Server, /** Server page. */
Directories, /** Directories page. */
Appearance, /** Appearance page. */
Notify /** Notify page. */
};
/** Default Constructor */
Appearance, /** Appearance page. */
Notify, /** Notify page. */
FileAssotiations /** File assotiations page. */
};
/** Default Constructor */
PreferencesWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default destructor */
//~PreferencesWindow();
//~PreferencesWindow();
protected:
void closeEvent (QCloseEvent * event);
public slots:
/** Called when this dialog is to be displayed */
//void show();
/** Shows the Preferences dialog with focus set to the given page. */
void showWindow(Page page);
private slots:
/** Called when user clicks "Save Settings" */
void saveChanges();
public slots:
/** Called when this dialog is to be displayed */
//void show();
/** Shows the Preferences dialog with focus set to the given page. */
void showWindow(Page page);
private slots:
/** Called when user clicks "Save Settings" */
void saveChanges();
/**void preferences();*/
void cancelpreferences();
@ -85,19 +86,19 @@ private slots:
* topic. */
void showHelp();
/** Called when a child window requests the given help <b>topic</b>. */
void showHelp(const QString &topic);
private:
/** Loads the current configuration settings */
void loadSettings();
/** Creates a new action for a config page. */
QAction* createPageAction(QIcon img, QString text, QActionGroup *group);
/** Adds a new action to the toolbar. */
void addAction(QAction *action, const char *slot = 0);
/** Qt Designer generated object */
Ui::PreferencesWindow ui;
};
#endif
void showHelp(const QString &topic);
private:
/** Loads the current configuration settings */
void loadSettings();
/** Creates a new action for a config page. */
QAction* createPageAction(QIcon img, QString text, QActionGroup *group);
/** Adds a new action to the toolbar. */
void addAction(QAction *action, const char *slot = 0);
/** Qt Designer generated object */
Ui::PreferencesWindow ui;
};
#endif