Beispiel #1
0
EditDialog::EditDialog(QString name, QString desc, QString cmd): QDialog() {
	// editing
	QLabel *lname = new QLabel;
	lname->setText(tr("Name"));
	name_ = new QLineEdit;
	name_->setText(name);
	if (applications_check_default(name.toLocal8Bit().data()))
		name_->setEnabled(false);

	QLabel *ldesc = new QLabel;
	ldesc->setText(tr("Description"));
	desc_ = new QLineEdit;
	desc_->setText(desc);

 	QLabel *lcmd = new QLabel;
	lcmd->setText(tr("Command"));
	cmd_ = new QLineEdit;
	cmd_->setText(cmd);

	// buttons
    	QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                     | QDialogButtonBox::Cancel);
	connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
	connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
	QPushButton *helpButton = new QPushButton("Help");
	connect(helpButton, SIGNAL(pressed()), this, SLOT(help()));

	// layout- editing
	QGridLayout *layout = new QGridLayout;
	layout->addItem(new QSpacerItem(30, 15), 0, 0);
	layout->addItem(new QSpacerItem(400, 15), 0, 2);
	layout->addItem(new QSpacerItem(30, 15), 0, 3);
	layout->addWidget(lname, 1, 1);
	layout->addWidget(name_, 1, 2);
	layout->addWidget(ldesc, 2, 1);
	layout->addWidget(desc_, 2, 2);
	layout->addWidget(lcmd, 3, 1);
	layout->addWidget(cmd_, 3, 2);
	layout->addItem(new QSpacerItem(30, 15), 4, 0);
	
	// layout - buttons
	layout->addItem(new QSpacerItem(30, 30), 5, 0);
	layout->addWidget(helpButton, 6, 1);
	layout->addWidget(buttonBox, 6, 2);
	layout->addItem(new QSpacerItem(30, 15), 7, 0);
	setLayout(layout);
//	resize(600, 500);
	setWindowTitle(tr("Edit Sandbox"));
}	
Beispiel #2
0
void MainWindow::edit() {
	if (edit_index_ != -1) {
		EditDialog *edit;
		
		// new entry
		if (active_index_ == -1) {
			edit = new EditDialog("", "", "");
			if (QDialog::Accepted == edit->exec()) {
				// check if the sandbox already exists
				QString name = edit->getName();
				if (applist_check(name) == false && applications_check_default(name.toLocal8Bit().constData()) == false) {
					Application app(edit->getName(), edit->getDescription(), edit->getCommand(), edit->getName());
					app.saveConfig();
					applist.append(app);
					if (arg_debug) {
						printf("Application added:\n");
						applist_print();
					}
				}
				else
					QMessageBox::critical(this, tr("Firejail Tools"),
						tr("<br/>Sandbox already defined.<br/><br/><br/>"));
				
			}
		}
		
		// existing entry
		else {
//printf("%s\n", applist[active_index_].exec_.toLocal8Bit().constData());
			edit = new EditDialog(applist[active_index_].name_, applist[active_index_].description_, applist[active_index_].exec_);
			if (QDialog::Accepted == edit->exec()) {
				applist[active_index_].name_ = edit->getName();
				applist[active_index_].description_ = edit->getDescription();
				applist[active_index_].exec_ = edit->getCommand();
				applist[active_index_].saveConfig();
			}
		}
		delete edit;
		
		// update
		hide();
		show();
		update();
	}
}
void MainWindow::mousePressEvent(QMouseEvent *event) {
	int nelem = applist.count();
	int cols = nelem / ROWS + 1;

	if (event->button() == Qt::LeftButton) {
		int x = event->pos().x();
		int y = event->pos().y();
		if (x >= MARGIN * 2 + cols * 64 - 8 && x <= MARGIN * 2 + cols * 64 + 4 &&
			   y >= 4 && y <= 15) {
			hide();
			stats_->hide();
		}
		else if (x >= 0 && x < 64 &&
			   y >= 4 && y <= 15)
			   runTools();
		dragPosition_ = event->globalPos() - frameGeometry().topLeft();
		event->accept();
		active_index_ = -1;
	}

	else if (event->button() == Qt::RightButton) {
		active_index_ = applications_get_index(event->pos());
		edit_index_ = active_index_;
		if (active_index_ == -1) {
			qrun_->setDisabled(true);
			edit_index_ = applications_get_position(event->pos());
			if (edit_index_ == -1)
				qedit_->setDisabled(true);
			else
				qedit_->setDisabled(false);
			qdelete_->setDisabled(true);
		}
		else {
			qrun_->setDisabled(false);
			qedit_->setDisabled(false);
			if (applications_check_default(applist[active_index_].name_.toLocal8Bit().constData()))
				qdelete_->setDisabled(true);
			else
				qdelete_->setDisabled(false);
		}
	}
}