From owner-p4-projects@FreeBSD.ORG Mon Jul 27 17:08:25 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id CC45D1065742; Mon, 27 Jul 2009 17:08:24 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8821D106574F for ; Mon, 27 Jul 2009 17:08:24 +0000 (UTC) (envelope-from jona@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 6BE0F8FC0A for ; Mon, 27 Jul 2009 17:08:24 +0000 (UTC) (envelope-from jona@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n6RH8Oe8013234 for ; Mon, 27 Jul 2009 17:08:24 GMT (envelope-from jona@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n6RH8Ods013232 for perforce@freebsd.org; Mon, 27 Jul 2009 17:08:24 GMT (envelope-from jona@FreeBSD.org) Date: Mon, 27 Jul 2009 17:08:24 GMT Message-Id: <200907271708.n6RH8Ods013232@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jona@FreeBSD.org using -f From: Jonathan Anderson To: Perforce Change Reviews Cc: Subject: PERFORCE change 166634 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jul 2009 17:08:25 -0000 http://perforce.freebsd.org/chv.cgi?CH=166634 Change 166634 by jona@jona-trustedbsd-belle-vmware on 2009/07/27 17:07:23 Use a standard Qt Designer-based UI Affected files ... .. //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_qt/TextEditor.cpp#4 edit .. //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_qt/TextEditor.h#3 edit .. //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_qt/TextEditor.ui#1 add .. //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_qt/sandbox_qt.cpp#8 edit .. //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_qt/sandbox_qt.pro#5 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_qt/TextEditor.cpp#4 (text+ko) ==== @@ -44,53 +44,15 @@ TextEditor::TextEditor() - : QMainWindow(), currentFile(this) + : QMainWindow() { - setAttribute(Qt::WA_QuitOnClose); - setWindowTitle(tr("Sandboxed Text Editor")); - - openFile = new QAction(QIcon(":/icons/open.png"), tr("&Open..."), this); - openFile->setShortcuts(QKeySequence::Open); - openFile->setStatusTip(tr("Open an existing file")); - connect(openFile, SIGNAL(triggered()), this, SLOT(open())); + ui.setupUi(this); + connect(ui.actionOpen, SIGNAL(activated()), this, SLOT(open())); + connect(ui.actionOpenRaw, SIGNAL(activated()), this, SLOT(openRaw())); + connect(ui.actionSave, SIGNAL(activated()), this, SLOT(save())); + connect(ui.actionClose, SIGNAL(activated()), this, SLOT(close())); + connect(ui.actionQuit, SIGNAL(activated()), this, SLOT(quit())); - saveFile = new QAction(QIcon(":/icons/save.png"), tr("&Save..."), this); - saveFile->setShortcuts(QKeySequence::Save); - saveFile->setStatusTip(tr("Save the file")); - connect(saveFile, SIGNAL(triggered()), this, SLOT(save())); - - openFileRaw = new QAction(QIcon(":/icons/open.png"), - tr("&Open via raw syscalls..."), this); - openFileRaw->setStatusTip(tr("Open a file via raw system calls")); - connect(openFileRaw, SIGNAL(triggered()), this, SLOT(openRaw())); - - closeFile = new QAction(QIcon(":/icons/close.png"), tr("&Close..."), this); - closeFile->setShortcuts(QKeySequence::Close); - closeFile->setStatusTip(tr("Close the current file")); - connect(closeFile, SIGNAL(triggered()), this, SLOT(close())); - - quitEditor = new QAction(QIcon(":/icons/quit.png"), tr("&Quit"), this); - quitEditor->setShortcut(QKeySequence("Ctrl+Q")); - quitEditor->setStatusTip(tr("Quit Text Editor")); - connect(quitEditor, SIGNAL(triggered()), this, SLOT(quit())); - - fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(openFile); - fileMenu->addAction(openFileRaw); - fileMenu->addAction(saveFile); - fileMenu->addAction(closeFile); - fileMenu->addAction(quitEditor); - - fileToolBar = addToolBar("File"); - fileToolBar->addAction(openFile); - fileToolBar->addAction(openFileRaw); - fileToolBar->addAction(saveFile); - fileToolBar->addAction(closeFile); - fileToolBar->addAction(quitEditor); - - setCentralWidget(text = new QTextEdit()); - - resize(640, 480); show(); } @@ -103,6 +65,8 @@ void TextEditor::open() { + close(); + struct ua_powerbox_options options; options.ui = UA_QT; options.operation = UA_OPEN_FILE; @@ -129,48 +93,46 @@ return; } - currentFile.open(fdopen(fd, "rw"), QFile::ReadWrite); - text->setPlainText(currentFile.readAll()); + QFile file(this); + file.open(fd, QFile::ReadWrite | QFile::Unbuffered); + ui.text->setPlainText(file.readAll()); + file.close(); } void TextEditor::save() { - if(!currentFile.isOpen()) - { - struct ua_powerbox_options options; - options.ui = UA_QT; - options.operation = UA_SAVE_FILE; - options.parent_window = this->winId(); - options.start_path = ""; - options.pathlen = 0; - options.start_fd = -1; - options.mult = false; - options.filter = ""; - options.filterlen = 0; - options.flags = O_WRONLY | O_CREAT | O_TRUNC; - options.rights = CAP_FSTAT | CAP_SEEK | CAP_FSYNC | CAP_READ | CAP_WRITE | CAP_FTRUNCATE; - options.umask = 0666; + struct ua_powerbox_options options; + options.ui = UA_QT; + options.operation = UA_SAVE_FILE; + options.parent_window = this->winId(); + options.start_path = ""; + options.pathlen = 0; + options.start_fd = -1; + options.mult = false; + options.filter = ""; + options.filterlen = 0; + options.flags = O_WRONLY | O_CREAT | O_TRUNC; + options.rights = CAP_FSTAT | CAP_SEEK | CAP_FSYNC | CAP_READ | CAP_WRITE | CAP_FTRUNCATE; + options.umask = 0666; - int fdcount = 1; - int fd; - char *name; + int fdcount = 1; + int fd; + char *name; - if(ua_powerbox(&options, &fd, &name, &fdcount)) - { - QMessageBox::critical(this, - tr("Powerbox Error"), - tr("Error opening User Angel powerbox: ") - + strerror(errno)); - return; - } - - currentFile.open(fd, QFile::ReadWrite); + if(ua_powerbox(&options, &fd, &name, &fdcount)) + { + QMessageBox::critical(this, + tr("Powerbox Error"), + tr("Error opening User Angel powerbox: ") + + strerror(errno)); + return; } - currentFile.resize(0); - currentFile.write(text->toPlainText().toAscii()); - currentFile.flush(); + QFile file(this); + file.open(fd, QFile::ReadWrite | QFile::Truncate); + file.write(ui.text->toPlainText().toAscii()); + file.flush(); } @@ -187,8 +149,7 @@ void TextEditor::close() { - currentFile.close(); - text->setPlainText(""); + ui.text->setPlainText(""); } ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_qt/TextEditor.h#3 (text+ko) ==== @@ -31,8 +31,10 @@ * SUCH DAMAGE. */ +#include "ui_TextEditor.h" + +#include #include -#include class QAction; class QMenu; @@ -58,17 +60,6 @@ private: - QTextEdit *text; - - QMenu *fileMenu; - QToolBar *fileToolBar; - - QAction *openFile; - QAction *saveFile; - QAction *openFileRaw; - QAction *closeFile; - QAction *quitEditor; - - QFile currentFile; + Ui::TextEditor ui; }; ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_qt/sandbox_qt.cpp#8 (text+ko) ==== @@ -61,6 +61,8 @@ #include +#include "TextEditor.h" + #include #include #include @@ -69,8 +71,6 @@ #include #include -#include "TextEditor.h" - using namespace std; ==== //depot/projects/trustedbsd/capabilities/src/tools/cap/sandbox_qt/sandbox_qt.pro#5 (text+ko) ==== @@ -9,6 +9,7 @@ QMAKE_LFLAGS += -rdynamic # Input +FORMS = TextEditor.ui HEADERS = TextEditor.h SOURCES = sandbox_qt.cpp TextEditor.cpp xcb_auth.c RESOURCES = TextEditor.qrc