mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
ab43d876c8
commit
22c2974466
@ -193,6 +193,8 @@ HEADERS += rshare.h \
|
||||
gui/Preferences/ConfirmQuitDialog.h \
|
||||
gui/Preferences/rsharesettings.h \
|
||||
gui/Preferences/rsettings.h \
|
||||
gui/Preferences/FileAssotiationsDialog.h \
|
||||
gui/Preferences/AddFileAssotiationDialog.h \
|
||||
gui/toaster/MessageToaster.h \
|
||||
gui/toaster/OnlineToaster.h \
|
||||
gui/toaster/ChatToaster.h \
|
||||
@ -417,6 +419,8 @@ SOURCES += main.cpp \
|
||||
gui/Preferences/ConfirmQuitDialog.cpp \
|
||||
gui/Preferences/rsharesettings.cpp \
|
||||
gui/Preferences/rsettings.cpp \
|
||||
gui/Preferences/FileAssotiationsDialog.cpp \
|
||||
gui/Preferences/AddFileAssotiationDialog.cpp \
|
||||
gui/common/vmessagebox.cpp \
|
||||
gui/common/rwindow.cpp \
|
||||
gui/common/html.cpp \
|
||||
|
228
retroshare-gui/src/gui/Preferences/AddFileAssotiationDialog.cpp
Normal file
228
retroshare-gui/src/gui/Preferences/AddFileAssotiationDialog.cpp
Normal 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 );
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
|
||||
|
@ -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
|
||||
|
379
retroshare-gui/src/gui/Preferences/FileAssotiationsDialog.cpp
Executable file
379
retroshare-gui/src/gui/Preferences/FileAssotiationsDialog.cpp
Executable 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" ;
|
||||
|
||||
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
||||
|
||||
|
90
retroshare-gui/src/gui/Preferences/FileAssotiationsDialog.h
Executable file
90
retroshare-gui/src/gui/Preferences/FileAssotiationsDialog.h
Executable 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
|
@ -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);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "ServerPage.h"
|
||||
#include "NetworkPage.h"
|
||||
#include "gsettingswin.h"
|
||||
//#include "FileAssotiationsDialog.h"
|
||||
|
||||
GSettingsWin::GSettingsWin(QWidget * parent, Qt::WFlags flags)
|
||||
: QDialog(parent, flags)
|
||||
@ -58,6 +59,7 @@ GSettingsWin::initStackedWidget()
|
||||
stackedWidget->addWidget(new NetworkPage());
|
||||
stackedWidget->addWidget(new ServerPage());
|
||||
stackedWidget->addWidget(new DirectoriesPage());
|
||||
// stackedWidget->addWidget(new FileAssotiationsDialog() );
|
||||
|
||||
|
||||
setNewPage(General);
|
||||
@ -70,17 +72,28 @@ GSettingsWin::setNewPage(int page)
|
||||
{
|
||||
QString text;
|
||||
|
||||
if (page == General)
|
||||
text = tr("General");
|
||||
else if (page == Network)
|
||||
text = tr("Network");
|
||||
else if (page == Directories)
|
||||
text = tr("Directories");
|
||||
else if (page == Server)
|
||||
|
||||
text = tr("Server");
|
||||
|
||||
pageName->setText(tr("%1").arg(text));
|
||||
switch (page)
|
||||
{
|
||||
case General:
|
||||
text = tr("General");
|
||||
break;
|
||||
case Network:
|
||||
text = tr("Network");
|
||||
break;
|
||||
case Directories:
|
||||
text = tr("Directories");
|
||||
break;
|
||||
case Server:
|
||||
text = tr("Server");
|
||||
break;
|
||||
case FileAssotiations:
|
||||
text = tr("File assotiations");
|
||||
break;
|
||||
default:
|
||||
text = tr("UnknownPage");// impossible case
|
||||
}
|
||||
|
||||
pageName->setText(text); //tr("%1").arg(
|
||||
stackedWidget->setCurrentIndex(page);
|
||||
listWidget->setCurrentRow(page);
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ class GSettingsWin: public QDialog, private Ui::Settings
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum PageType { General = 0, Network, Server, Directories };
|
||||
enum PageType { General = 0, Network, Server,
|
||||
Directories, FileAssotiations };
|
||||
|
||||
GSettingsWin(QWidget * parent = 0, Qt::WFlags flags = 0);
|
||||
~GSettingsWin() {}
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "rshare.h"
|
||||
#include "SharedFilesDialog.h"
|
||||
#include "Preferences/AddFileAssotiationDialog.h"
|
||||
|
||||
#include "rsiface/rsiface.h"
|
||||
#include "rsiface/rspeers.h"
|
||||
@ -29,6 +30,7 @@
|
||||
#include "rsiface/RemoteDirModel.h"
|
||||
#include "util/RsAction.h"
|
||||
#include "msgs/ChanMsgDialog.h"
|
||||
#include "Preferences/rsharesettings.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@ -45,6 +47,9 @@
|
||||
#include <QMovie>
|
||||
#include <QLabel>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
|
||||
/* Images for context menu icons */
|
||||
#define IMAGE_DOWNLOAD ":/images/download16.png"
|
||||
#define IMAGE_PLAY ":/images/start.png"
|
||||
@ -54,6 +59,7 @@
|
||||
#define IMAGE_ATTACHMENT ":/images/attachment.png"
|
||||
#define IMAGE_FRIEND ":/images/peers_16x16.png"
|
||||
#define IMAGE_PROGRESS ":/images/browse-looking.gif"
|
||||
const QString Image_AddNewAssotiationForFile = ":/images/kcmsystem24.png";
|
||||
|
||||
|
||||
/** Constructor */
|
||||
@ -69,7 +75,8 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
|
||||
|
||||
//connect(ui.frameButton, SIGNAL(toggled(bool)), this, SLOT(showFrame(bool)));
|
||||
|
||||
connect( ui.localDirTreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( shareddirtreeWidgetCostumPopupMenu( QPoint ) ) );
|
||||
connect( ui.localDirTreeView, SIGNAL( customContextMenuRequested( QPoint ) ),
|
||||
this, SLOT( sharedDirTreeWidgetContextMenu( QPoint ) ) );
|
||||
|
||||
connect( ui.remoteDirTreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( shareddirtreeviewCostumPopupMenu( QPoint ) ) );
|
||||
|
||||
@ -180,10 +187,9 @@ void SharedFilesDialog::forceCheck()
|
||||
|
||||
void SharedFilesDialog::shareddirtreeviewCostumPopupMenu( QPoint point )
|
||||
{
|
||||
|
||||
QMenu contextMnu( this );
|
||||
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
||||
|
||||
|
||||
downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), this );
|
||||
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) );
|
||||
|
||||
@ -377,14 +383,24 @@ void SharedFilesDialog::postModDirectories(bool update_local)
|
||||
}
|
||||
|
||||
|
||||
void SharedFilesDialog::shareddirtreeWidgetCostumPopupMenu( QPoint point )
|
||||
void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point )
|
||||
{
|
||||
//=== at this moment we'll show menu only for files, not for folders
|
||||
QModelIndex midx = ui.localDirTreeView->indexAt(point);
|
||||
if (localModel->isDir( midx ) )
|
||||
return;
|
||||
|
||||
QMenu contextMnu2( this );
|
||||
QMouseEvent *mevent2 = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
||||
currentFile = localModel->data(midx,
|
||||
RemoteDirModel::FileNameRole).toString();
|
||||
|
||||
openfolderAct = new QAction(QIcon(IMAGE_PLAY), tr( "Play File(s)" ), this );
|
||||
connect( openfolderAct , SIGNAL( triggered() ), this, SLOT( playselectedfiles() ) );
|
||||
QMenu contextMnu2( this );
|
||||
//
|
||||
|
||||
QAction* menuAction = fileAssotiationAction(currentFile) ;
|
||||
//new QAction(QIcon(IMAGE_PLAY), currentFile, this);
|
||||
//tr( "111Play File(s)" ), this );
|
||||
// connect( openfolderAct , SIGNAL( triggered() ), this,
|
||||
// SLOT( playselectedfiles() ) );
|
||||
|
||||
#if 0
|
||||
openfileAct = new QAction(QIcon(IMAGE_ATTACHMENT), tr( "Add to Recommend List" ), this );
|
||||
@ -441,18 +457,96 @@ void SharedFilesDialog::shareddirtreeWidgetCostumPopupMenu( QPoint point )
|
||||
#endif
|
||||
|
||||
|
||||
contextMnu2.addAction( openfolderAct);
|
||||
contextMnu2.addAction( menuAction );
|
||||
//contextMnu2.addAction( openfileAct);
|
||||
//contextMnu2.addSeparator();
|
||||
//contextMnu2.addMenu( recMenu);
|
||||
//contextMnu2.addMenu( msgMenu);
|
||||
|
||||
|
||||
contextMnu2.exec( mevent2->globalPos() );
|
||||
QMouseEvent *mevent2 = new QMouseEvent( QEvent::MouseButtonPress, point,
|
||||
Qt::RightButton, Qt::RightButton,
|
||||
Qt::NoModifier );
|
||||
contextMnu2.exec( mevent2->globalPos() );
|
||||
|
||||
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
||||
QAction*
|
||||
SharedFilesDialog::fileAssotiationAction(const QString fileName)
|
||||
{
|
||||
QAction* result = 0;
|
||||
|
||||
RshareSettings* settings = new RshareSettings();
|
||||
//QSettings* settings= new QSettings(qApp->applicationDirPath()+"/sett.ini",
|
||||
// QSettings::IniFormat);
|
||||
settings->beginGroup("FileAssotiations");
|
||||
|
||||
QString key = AddFileAssotiationDialog::cleanFileType(currentFile) ;
|
||||
if ( settings->contains(key) )
|
||||
{
|
||||
result = new QAction(QIcon(IMAGE_PLAY), tr( "Open File" ), this );
|
||||
connect( result , SIGNAL( triggered() ),
|
||||
this, SLOT( runCommandForFile() ) );
|
||||
|
||||
currentCommand = (settings->value( key )).toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new QAction(QIcon(Image_AddNewAssotiationForFile),
|
||||
tr( "Set command for opening this file"), this );
|
||||
connect( result , SIGNAL( triggered() ),
|
||||
this, SLOT( tryToAddNewAssotiation() ) );
|
||||
}
|
||||
|
||||
delete settings;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
||||
void
|
||||
SharedFilesDialog::runCommandForFile()
|
||||
{
|
||||
QStringList tsl;
|
||||
tsl.append( currentFile );
|
||||
QProcess::execute( currentCommand, tsl);
|
||||
//QString("%1 %2").arg(currentCommand).arg(currentFile) );
|
||||
|
||||
// QString tmess = "Some command(%1) should be executed here for file %2";
|
||||
// tmess = tmess.arg(currentCommand).arg(currentFile);
|
||||
// QMessageBox::warning(this, tr("RetroShare"), tmess, QMessageBox::Ok);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
||||
void
|
||||
SharedFilesDialog::tryToAddNewAssotiation()
|
||||
{
|
||||
AddFileAssotiationDialog afad(true, this);//'add file assotiations' dialog
|
||||
|
||||
afad.setFileType(AddFileAssotiationDialog::cleanFileType(currentFile));
|
||||
|
||||
int ti = afad.exec();
|
||||
|
||||
if (ti==QDialog::Accepted)
|
||||
{
|
||||
RshareSettings* settings = new RshareSettings();
|
||||
//QSettings settings( qApp->applicationDirPath()+"/sett.ini",
|
||||
// QSettings::IniFormat);
|
||||
settings->beginGroup("FileAssotiations");
|
||||
|
||||
QString currType = afad.resultFileType() ;
|
||||
QString currCmd = afad.resultCommand() ;
|
||||
|
||||
settings->setValue(currType, currCmd);
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
/**
|
||||
Toggles the Lokal TreeView on and off, changes toggle button text
|
||||
|
||||
|
@ -55,7 +55,7 @@ private slots:
|
||||
/** Create the context popup menu and it's submenus */
|
||||
void shareddirtreeviewCostumPopupMenu( QPoint point );
|
||||
|
||||
void shareddirtreeWidgetCostumPopupMenu( QPoint point );
|
||||
void sharedDirTreeWidgetContextMenu( QPoint point );
|
||||
|
||||
void downloadRemoteSelected();
|
||||
// void addMsgRemoteSelected();
|
||||
@ -71,15 +71,19 @@ private slots:
|
||||
// void recommendFileSetOnly();
|
||||
// void recommendFilesTo( std::string rsid );
|
||||
// void recommendFilesToMsg( std::string rsid );
|
||||
void runCommandForFile();
|
||||
void tryToAddNewAssotiation();
|
||||
|
||||
signals:
|
||||
void playFiles(QStringList files);
|
||||
|
||||
private:
|
||||
/** Define the popup menus for the Context menu */
|
||||
QMenu* contextMnu;
|
||||
//now context menu are created again every time theu are called ( in some
|
||||
//slots.. Maybe it's not good...
|
||||
//** Define the popup menus for the Context menu */
|
||||
//QMenu* contextMnu;
|
||||
|
||||
QMenu* contextMnu2;
|
||||
//QMenu* contextMnu2;
|
||||
|
||||
/** Defines the actions for the context menu for QTreeView */
|
||||
QAction* downloadAct;
|
||||
@ -99,6 +103,11 @@ private:
|
||||
/* RemoteDirModel */
|
||||
RemoteDirModel *model;
|
||||
RemoteDirModel *localModel;
|
||||
|
||||
QString currentCommand;
|
||||
QString currentFile;
|
||||
|
||||
QAction* fileAssotiationAction(const QString fileName);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -231,6 +231,14 @@ RemoteDirModel::RemoteDirModel(bool mode, QObject *parent)
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
|
||||
if (role == RemoteDirModel::FileNameRole)
|
||||
{
|
||||
FileInfo finfo;
|
||||
rsFiles->FileDetails(details.hash, 0, finfo);
|
||||
|
||||
return QString::fromStdString(finfo.path) ;
|
||||
}
|
||||
|
||||
if (role == Qt::DecorationRole)
|
||||
{
|
||||
@ -1043,6 +1051,31 @@ QStringList RemoteDirModel::mimeTypes () const
|
||||
return list;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
||||
bool
|
||||
RemoteDirModel::isDir ( const QModelIndex & index ) const
|
||||
{
|
||||
//if (RemoteMode) // only local files can be opened
|
||||
// return ;
|
||||
void *ref = index.internalPointer();
|
||||
if (!ref)
|
||||
return false;
|
||||
|
||||
DirDetails details;
|
||||
uint32_t flags = DIR_FLAGS_DETAILS;
|
||||
if (RemoteMode)
|
||||
flags |= DIR_FLAGS_REMOTE;
|
||||
else
|
||||
flags |= DIR_FLAGS_LOCAL;
|
||||
|
||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||
{
|
||||
return false;//not good, but....
|
||||
}
|
||||
|
||||
return (details.type == DIR_TYPE_DIR) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -8,10 +8,12 @@
|
||||
#include "util/misc.h"
|
||||
|
||||
class RemoteDirModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Roles{ FileNameRole = Qt::UserRole+1 };
|
||||
|
||||
RemoteDirModel(bool mode, QObject *parent = 0);
|
||||
|
||||
/* These are all overloaded Virtual Functions */
|
||||
@ -36,6 +38,9 @@ class RemoteDirModel : public QAbstractItemModel
|
||||
/* Callback from GUI */
|
||||
void downloadSelected(QModelIndexList list);
|
||||
|
||||
bool isDir ( const QModelIndex & index ) const ;
|
||||
//void openFile(QModelIndex fileIndex, const QString command);
|
||||
|
||||
#if 0 /****** REMOVED ******/
|
||||
void recommendSelected(QModelIndexList list);
|
||||
void recommendSelectedOnly(QModelIndexList list);
|
||||
|
Loading…
Reference in New Issue
Block a user