2021-07-05 12:37:28 +01:00
# include "stdafx.h"
# include "SelectBoxWindow.h"
# include "SandMan.h"
# include "../MiscHelpers/Common/Settings.h"
# include "../SbiePlusAPI.h"
# if defined(Q_OS_WIN)
# include <wtypes.h>
# include <QAbstractNativeEventFilter>
# include <dbt.h>
# endif
2021-08-08 09:23:53 +01:00
CSelectBoxWindow : : CSelectBoxWindow ( const QStringList & Commands , const QString & BoxName , QWidget * parent )
2021-07-05 12:37:28 +01:00
: QDialog ( parent )
{
m_Commands = Commands ;
Qt : : WindowFlags flags = windowFlags ( ) ;
flags | = Qt : : CustomizeWindowHint ;
//flags &= ~Qt::WindowContextHelpButtonHint;
//flags &= ~Qt::WindowSystemMenuHint;
//flags &= ~Qt::WindowMinMaxButtonsHint;
//flags |= Qt::WindowMinimizeButtonHint;
//flags &= ~Qt::WindowCloseButtonHint;
flags & = ~ Qt : : WindowContextHelpButtonHint ;
//flags &= ~Qt::WindowSystemMenuHint;
setWindowFlags ( flags ) ;
//setWindowState(Qt::WindowActive);
SetForegroundWindow ( ( HWND ) QWidget : : winId ( ) ) ;
ui . setupUi ( this ) ;
this - > setWindowTitle ( tr ( " Sandboxie-Plus - Run Sandboxed " ) ) ;
connect ( ui . radBoxed , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnBoxType ( ) ) ) ;
connect ( ui . radUnBoxed , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnBoxType ( ) ) ) ;
connect ( ui . buttonBox , SIGNAL ( accepted ( ) ) , SLOT ( OnRun ( ) ) ) ;
connect ( ui . buttonBox , SIGNAL ( rejected ( ) ) , SLOT ( reject ( ) ) ) ;
QMap < QString , CSandBoxPtr > Boxes = theAPI - > GetAllBoxes ( ) ;
foreach ( const CSandBoxPtr & pBox , Boxes )
{
2021-07-10 11:59:32 +01:00
if ( ! pBox - > IsEnabled ( ) | | ! pBox - > GetBool ( " ShowForRunIn " , true ) )
continue ;
2021-07-05 12:37:28 +01:00
CSandBoxPlus * pBoxEx = qobject_cast < CSandBoxPlus * > ( pBox . data ( ) ) ;
QTreeWidgetItem * pItem = new QTreeWidgetItem ( ) ;
pItem - > setText ( 0 , pBox - > GetName ( ) . replace ( " _ " , " " ) ) ;
pItem - > setData ( 0 , Qt : : UserRole , pBox - > GetName ( ) ) ;
pItem - > setData ( 0 , Qt : : DecorationRole , theGUI - > GetBoxIcon ( pBox - > GetActiveProcessCount ( ) , pBoxEx - > GetType ( ) ) ) ;
ui . treeBoxes - > addTopLevelItem ( pItem ) ;
2021-08-08 09:23:53 +01:00
if ( pBox - > GetName ( ) . compare ( BoxName , Qt : : CaseInsensitive ) = = 0 )
2021-07-05 12:37:28 +01:00
ui . treeBoxes - > setCurrentItem ( pItem ) ;
}
//restoreGeometry(theConf->GetBlob("SelectBoxWindow/Window_Geometry"));
}
CSelectBoxWindow : : ~ CSelectBoxWindow ( )
{
//theConf->SetBlob("SelectBoxWindow/Window_Geometry", saveGeometry());
}
void CSelectBoxWindow : : closeEvent ( QCloseEvent * e )
{
//emit Closed();
this - > deleteLater ( ) ;
}
void CSelectBoxWindow : : OnBoxType ( )
{
ui . treeBoxes - > setEnabled ( ! ui . radUnBoxed - > isChecked ( ) ) ;
}
void CSelectBoxWindow : : OnRun ( )
{
QTreeWidgetItem * pItem = ui . treeBoxes - > currentItem ( ) ;
QString BoxName ;
if ( ui . radUnBoxed - > isChecked ( ) )
{
2021-07-18 20:14:38 +01:00
if ( QMessageBox ( " Sandboxie-Plus " , tr ( " Are you sure you want to run the program outside the sandbox? " ) , QMessageBox : : Question , QMessageBox : : Yes , QMessageBox : : No | QMessageBox : : Default | QMessageBox : : Escape , QMessageBox : : NoButton , this ) . exec ( ) ! = QMessageBox : : Yes )
2021-07-05 12:37:28 +01:00
return ;
pItem = NULL ;
}
else if ( pItem = = NULL ) {
QMessageBox ( " Sandboxie-Plus " , tr ( " Please select a sandbox. " ) , QMessageBox : : Information , QMessageBox : : Ok , QMessageBox : : NoButton , QMessageBox : : NoButton , this ) . exec ( ) ;
return ;
}
else {
BoxName = pItem - > data ( 0 , Qt : : UserRole ) . toString ( ) ;
}
//QList<SB_STATUS> Results;
2021-07-10 09:42:39 +01:00
foreach ( const QString & Command , m_Commands ) {
theAPI - > RunStart ( BoxName , Command , NULL , ui . chkAdmin - > isChecked ( ) ) ;
2021-07-05 12:37:28 +01:00
}
//CSandMan::CheckResults(Results);
close ( ) ;
}