2010-04-08 12:33:10 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 - 2010 RetroShare Team
*
* 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 "ShareDialog.h"
2010-08-06 05:40:23 -04:00
# include <retroshare/rsfiles.h>
2010-04-08 12:33:10 -04:00
# include <QContextMenuEvent>
2010-09-17 14:27:30 -04:00
# include <QFileDialog>
2010-04-08 12:33:10 -04:00
# include <QMessageBox>
# include <QComboBox>
/** Default constructor */
ShareDialog : : ShareDialog ( QWidget * parent , Qt : : WFlags flags )
: QDialog ( parent , flags )
{
2010-09-17 14:27:30 -04:00
/* Invoke Qt Designer generated QObject setup routine */
ui . setupUi ( this ) ;
connect ( ui . browseButton , SIGNAL ( clicked ( bool ) ) , this , SLOT ( browseDirectory ( ) ) ) ;
connect ( ui . okButton , SIGNAL ( clicked ( bool ) ) , this , SLOT ( addDirectory ( ) ) ) ;
connect ( ui . closeButton , SIGNAL ( clicked ( ) ) , this , SLOT ( closedialog ( ) ) ) ;
2010-04-08 12:33:10 -04:00
2010-09-17 14:27:30 -04:00
ui . okButton - > setEnabled ( false ) ;
2010-04-08 12:33:10 -04:00
2010-09-17 14:27:30 -04:00
load ( ) ;
2010-04-08 12:33:10 -04:00
}
void ShareDialog : : load ( )
{
2010-09-17 14:27:30 -04:00
ui . localpath_lineEdit - > clear ( ) ;
ui . browsableCheckBox - > setChecked ( false ) ;
ui . networkwideCheckBox - > setChecked ( false ) ;
2010-04-08 12:33:10 -04:00
}
void ShareDialog : : browseDirectory ( )
{
2010-09-17 14:27:30 -04:00
/* select a dir*/
QString qdir = QFileDialog : : getExistingDirectory ( this , tr ( " Select A Folder To Share " ) , " " , QFileDialog : : DontUseNativeDialog | QFileDialog : : ShowDirsOnly | QFileDialog : : DontResolveSymlinks ) ;
/* add it to the server */
if ( qdir . isEmpty ( ) ) {
ui . okButton - > setEnabled ( false ) ;
return ;
}
ui . okButton - > setEnabled ( true ) ;
ui . localpath_lineEdit - > setText ( qdir ) ;
2010-04-08 12:33:10 -04:00
}
void ShareDialog : : addDirectory ( )
{
2010-09-17 14:27:30 -04:00
SharedDirInfo sdi ;
sdi . filename = ui . localpath_lineEdit - > text ( ) . toUtf8 ( ) . constData ( ) ;
sdi . virtualname = ui . virtualpath_lineEdit - > text ( ) . toUtf8 ( ) . constData ( ) ;
2010-04-08 12:33:10 -04:00
2010-09-17 14:27:30 -04:00
sdi . shareflags = 0 ;
2010-04-08 12:33:10 -04:00
2010-09-17 14:27:30 -04:00
if ( ui . browsableCheckBox - > isChecked ( ) ) {
sdi . shareflags | = RS_FILE_HINTS_BROWSABLE ;
}
if ( ui . networkwideCheckBox - > isChecked ( ) ) {
sdi . shareflags | = RS_FILE_HINTS_NETWORK_WIDE ;
}
rsFiles - > addSharedDirectory ( sdi ) ;
load ( ) ;
close ( ) ;
2010-04-08 12:33:10 -04:00
}
void ShareDialog : : showEvent ( QShowEvent * event )
{
2010-09-17 14:27:30 -04:00
if ( ! event - > spontaneous ( ) )
{
load ( ) ;
}
2010-04-08 12:33:10 -04:00
}
void ShareDialog : : closedialog ( )
{
2010-09-17 14:27:30 -04:00
ui . localpath_lineEdit - > clear ( ) ;
ui . browsableCheckBox - > setChecked ( false ) ;
ui . networkwideCheckBox - > setChecked ( false ) ;
2010-04-08 12:33:10 -04:00
2010-09-17 14:27:30 -04:00
close ( ) ;
2010-04-08 12:33:10 -04:00
}