PERFORCE change 166634 for review
Jonathan Anderson
jona at FreeBSD.org
Mon Jul 27 17:08:25 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166634
Change 166634 by jona at 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 <QMainWindow>
#include <QFile>
-#include <QMainWindow>
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 <iostream>
+#include "TextEditor.h"
+
#include <QApplication>
#include <QFile>
#include <QMessageBox>
@@ -69,8 +71,6 @@
#include <X11/Xauth.h>
#include <xcb/xcb.h>
-#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
More information about the p4-projects
mailing list