diff options
Diffstat (limited to 'src/pmquery')
-rw-r--r-- | src/pmquery/GNUmakefile | 76 | ||||
-rw-r--r-- | src/pmquery/main.cpp | 275 | ||||
-rwxr-xr-x | src/pmquery/pmconfirm.sh.in | 2 | ||||
-rwxr-xr-x | src/pmquery/pmmessage.sh.in | 2 | ||||
-rw-r--r-- | src/pmquery/pmquery.cpp | 316 | ||||
-rw-r--r-- | src/pmquery/pmquery.h | 105 | ||||
-rw-r--r-- | src/pmquery/pmquery.info.in | 18 | ||||
-rw-r--r-- | src/pmquery/pmquery.pro | 9 | ||||
-rw-r--r-- | src/pmquery/pmquery.qrc | 10 | ||||
-rw-r--r-- | src/pmquery/pmquery.sh.in | 2 |
10 files changed, 815 insertions, 0 deletions
diff --git a/src/pmquery/GNUmakefile b/src/pmquery/GNUmakefile new file mode 100644 index 0000000..c7cc628 --- /dev/null +++ b/src/pmquery/GNUmakefile @@ -0,0 +1,76 @@ +TOPDIR = ../.. +COMMAND = pmquery +PROJECT = $(COMMAND).pro +include $(TOPDIR)/src/include/builddefs + +WRAPPER = $(COMMAND).sh +QRCFILE = $(COMMAND).qrc +ICNFILE = $(COMMAND).icns +XMLFILE = $(COMMAND).info +HEADERS = pmquery.h +SOURCES = $(HEADERS:.h=.cpp) main.cpp +SCRIPTS = pmconfirm.sh pmmessage.sh +LSRCFILES = $(PROJECT) $(QRCFILE) $(SCRIPTS) $(HEADERS) $(SOURCES) \ + $(WRAPPER).in pmconfirm.sh.in pmmessage.sh.in $(XMLFILE).in +LDIRT = $(COMMAND) $(ICNFILE) $(WRAPPER) $(SCRIPTS) $(XMLFILE) images + +default: build-me + +include $(BUILDRULES) + +ifeq "$(ENABLE_QT)" "true" +build-me:: images wrappers + $(QTMAKE) + $(LNMAKE) + +ifeq ($(WINDOW),mac) +PKG_MAC_DIR = /Library/PCP/$(COMMAND).app/Contents +PKG_SUB_DIR = $(PKG_MAC_DIR)/MacOS +wrappers: $(WRAPPER) $(SCRIPTS) $(XMLFILE) +else +PKG_SUB_DIR = $(PCP_BIN_DIR) +wrappers: $(SCRIPTS) +endif + +$(WRAPPER): $(WRAPPER).in + @ $(SED) -e '/\# .*/b' -e 's;PCP_BIN_DIR;$(PKG_SUB_DIR);g' < $< > $@ +pmmessage.sh: pmmessage.sh.in + @ $(SED) -e '/\# .*/b' -e 's;PCP_BIN_DIR;$(PKG_SUB_DIR);g' < $< > $@ +pmconfirm.sh: pmconfirm.sh.in + @ $(SED) -e '/\# .*/b' -e 's;PCP_BIN_DIR;$(PKG_SUB_DIR);g' < $< > $@ +$(XMLFILE): $(XMLFILE).in + $(SED) -e 's;PACKAGE_VERSION;$(PACKAGE_VERSION);g' < $< > $@ + +install: default +ifneq ($(WINDOW),mac) + $(INSTALL) -m 755 $(BINARY) $(PCP_BIN_DIR)/$(COMMAND) +endif + $(INSTALL) -m 755 pmconfirm.sh $(PCP_BIN_DIR)/pmconfirm + $(INSTALL) -m 755 pmmessage.sh $(PCP_BIN_DIR)/pmmessage +ifeq ($(WINDOW),mac) + $(INSTALL) -m 755 $(WRAPPER) $(PCP_BIN_DIR)/$(COMMAND) + $(call INSTALL_DIRECTORY_HIERARCHY,$(PKG_MAC_DIR),/Library) + $(INSTALL) -m 644 $(XMLFILE) $(PKG_MAC_DIR)/Info.plist + $(INSTALL) -m 644 $(MACBUILD)/PkgInfo $(PKG_MAC_DIR)/PkgInfo + $(INSTALL) -m 755 -d $(PKG_MAC_DIR)/MacOS + $(call INSTALL_QT_FRAMEWORKS,$(BINARY)) + $(INSTALL) -m 755 $(BINARY) $(PKG_MAC_DIR)/MacOS/$(COMMAND) + rm $(BINARY) + $(INSTALL) -m 755 -d $(PKG_MAC_DIR)/Resources + $(INSTALL) -m 644 $(ICNFILE) $(PKG_MAC_DIR)/Resources/$(ICNFILE) + $(call INSTALL_QT_RESOURCES,$(PKG_MAC_DIR)/Resources) +endif +else +build-me: +install: +endif + +default_pcp: default + +install_pcp: install + +images: $(ICNFILE) + $(LN_S) $(TOPDIR)/images images + +$(ICNFILE): + $(LN_S) $(TOPDIR)/images/$(ICNFILE) $(ICNFILE) diff --git a/src/pmquery/main.cpp b/src/pmquery/main.cpp new file mode 100644 index 0000000..303761f --- /dev/null +++ b/src/pmquery/main.cpp @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2007, Aconex. All Rights Reserved. + * + * 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. + */ +#include <QtCore/QFile> +#include <QtCore/QTextStream> +#include <QtGui/QDesktopWidget> +#include <QtGui/QCursor> +#include "pmquery.h" + +static char usage[] = + "Usage: pmquery [options] [message...]\n\n" + "Options:\n" + " -c center the window on the display\n" + " -center display in the center (alias for -c)\n" + " -nearmouse pop up window near the mouse cursor\n" + " -b button create a button with the label button\n" + " -B button create the default button with the label button\n" + " -default button sets named button as the default button\n" + " -buttons string comma-separated list of label:exitcode\n" + " -h | -? | -help display this usage message\n" + " -t string add string to the message displayed\n" + " -file filename read message from file, \"-\" for stdin\n" + " -icon icontype dialog type: info, error, question, warning, critical,\n" + " host, or archive\n" + " -header title set window title\n" + " -useslider always display a text box slider\n" + " -noslider do not display a text box slider\n" + " -noframe do not display a frame around the text box\n" + " -print print the button label when selected\n" + " -noprint do not print the button label when selected\n" + " -timeout secs exit with status 0 after \"secs\" seconds\n" + " -exclusive do not allow mouse/button presses until dismissed\n"; + +char *getoption(int argc, char **argv) +{ + static int index; + + if (index >= argc) + return NULL; + return argv[++index]; +} + +char *catoption(char *prefix, char *option, int total) +{ + prefix = (char *)realloc(prefix, total); + if (prefix) { + strncat(prefix, " ", 2); + strncat(prefix, option, total); + } + return prefix; +} + +char *getoptions(int argc, char **argv, char *arg) +{ + int length = strlen(arg) + 1; + char *string = (char *)malloc(length); + strncpy(string, arg, length); + while (string && (arg = getoption(argc, argv)) != NULL) { + length += 1 + strlen(arg) + 1; + string = catoption(string, arg, length); + } + if (!string) { + fputs("Insufficient memory for buffering message\n", stderr); + exit(1); + } + return string; +} + +int main(int argc, char ** argv) +{ + char *option; + char *filename = NULL; + char *defaultname = NULL; + int errflag = 0; + int printflag = 1; + int inputflag = 0; + int centerflag = 0; + int noframeflag = 0; + int nosliderflag = 0; + int nearmouseflag = 0; + int usesliderflag = 0; + int exclusiveflag = 0; + + QApplication a(argc, argv); + + while ((option = getoption(argc, argv)) != NULL) { + if (strcmp(option, "-c") == 0 || strcmp(option, "-center") == 0) { + centerflag = 1; + } + else if (strcmp(option, "-nearmouse") == 0) { + nearmouseflag = 1; + } + else if (strcmp(option, "-b") == 0) { + if ((option = getoption(argc, argv)) == NULL) { + fprintf(stderr, "The -b option requires an argument\n"); + errflag++; + } + PmQuery::addButton(option, FALSE, 0); + } + else if (strcmp(option, "-B") == 0) { + if ((option = getoption(argc, argv)) == NULL) { + fprintf(stderr, "The -B option requires an argument\n"); + errflag++; + } + PmQuery::addButton(option, TRUE, 0); + } + else if (strcmp(option, "-default") == 0) { + if ((option = getoption(argc, argv)) == NULL) { + fprintf(stderr, "The -default option requires an argument\n"); + errflag++; + } + else defaultname = option; + } + else if (strcmp(option, "-buttons") == 0) { + if ((option = getoption(argc, argv)) == NULL) { + fprintf(stderr, "The -buttons option requires an argument\n"); + errflag++; + } + PmQuery::addButtons(option); + } + else if (strcmp(option, "-t") == 0) { + if ((option = getoption(argc, argv)) == NULL) { + fprintf(stderr, "The -B option requires an argument\n"); + errflag++; + } + else if (filename) { + fprintf(stderr, "The -file and -t options are incompatible\n"); + errflag++; + } + else PmQuery::addMessage(option); + } + else if (strcmp(option, "-file") == 0) { + if ((option = getoption(argc, argv)) == NULL) { + fprintf(stderr, "The -file option requires an argument\n"); + errflag++; + } + else if (PmQuery::messageCount()) { + fprintf(stderr, "The -file and -t options are incompatible\n"); + errflag++; + } + else filename = option; + } + else if (strcmp(option, "-icon") == 0) { + if ((option = getoption(argc, argv)) == NULL) { + fprintf(stderr, "The -icon option requires an argument\n"); + errflag++; + } + else if (PmQuery::setIcontype(option) < 0) { + fprintf(stderr, "Unknown icon type - %s\n", option); + errflag++; + } + } + else if (strcmp(option, "-header") == 0) { + if ((option = getoption(argc, argv)) == NULL) { + fprintf(stderr, "The -header option requires an argument\n"); + errflag++; + } + else PmQuery::setTitle(option); + } + else if (strcmp(option, "-input") == 0) { + inputflag = 1; + } + else if (strcmp(option, "-noframe") == 0) { + noframeflag = 1; + } + else if (strcmp(option, "-useslider") == 0) { + if (nosliderflag) { + fprintf(stderr, + "The -useslider and -noslider options are incompatible\n"); + errflag++; + } + else usesliderflag = 1; + } + else if (strcmp(option, "-noslider") == 0) { + if (usesliderflag) { + fprintf(stderr, + "The -useslider and -noslider options are incompatible\n"); + errflag++; + } + else nosliderflag = 1; + } + else if (strcmp(option, "-timeout") == 0) { + if ((option = getoption(argc, argv)) == NULL) { + fprintf(stderr, "The -timeout option requires an argument\n"); + errflag++; + } + else if (PmQuery::setTimeout(option) < 0) { + fprintf(stderr, "'%s' is not a positive non-zero timeout\n", + option); + errflag++; + } + } + else if (strcmp(option, "-print") == 0) { + printflag = 1; + } + else if (strcmp(option, "-noprint") == 0) { + printflag = 0; + } + else if (strcmp(option, "-exclusive") == 0) { + exclusiveflag = 1; + } + else if (strcmp(option, "-?") == 0 || strcmp(option, "-help") == 0 || + strcmp(option, "-h") == 0 || strcmp(option, "--help") == 0) { + errflag++; + } + else { + PmQuery::addMessage(getoptions(argc, argv, option)); + } + } + + if (errflag) { + fprintf(stderr, "%s", usage); + exit(1); + } + + if (defaultname) + PmQuery::setDefaultButton(defaultname); + + if (filename) { + QTextStream *stream; + QFile *file = NULL; + QString line; + + if (strcmp(filename, "-") == 0) + stream = new QTextStream(stdin, QIODevice::ReadOnly); + else { + file = new QFile(filename); + if (!file->open(QIODevice::ReadOnly)) { + fprintf(stderr, "Cannot open %s: %s\n", filename, + (char *)file->errorString().toAscii().data()); + exit(1); + } + stream = new QTextStream(file); + } + for (;;) { + QString line = stream->readLine(); + if (line.isNull()) + break; + if ((option = strdup(line.toAscii())) == NULL) { + fputs("Insufficient memory reading message stream\n", stderr); + exit(1); + } + PmQuery::addMessage(option); + } + if (file) + delete file; + delete stream; + } + + if (!PmQuery::buttonCount()) + PmQuery::addButton("Continue", TRUE, 0); + + PmQuery q(inputflag, printflag, noframeflag, + nosliderflag, usesliderflag, exclusiveflag); + + if (nearmouseflag) + q.move(QCursor::pos()); + else if (centerflag) { + int x = (a.desktop()->screenGeometry().width() / 2) - (q.width() / 2); + int y = (a.desktop()->screenGeometry().height() / 2) - (q.height() / 2); + q.move(x > 0 ? x : 0, y > 0 ? y : 0); + } + + return q.exec(); +} diff --git a/src/pmquery/pmconfirm.sh.in b/src/pmquery/pmconfirm.sh.in new file mode 100755 index 0000000..8fdaf49 --- /dev/null +++ b/src/pmquery/pmconfirm.sh.in @@ -0,0 +1,2 @@ +#!/bin/sh +exec PCP_BIN_DIR/pmquery -print "$@" diff --git a/src/pmquery/pmmessage.sh.in b/src/pmquery/pmmessage.sh.in new file mode 100755 index 0000000..5b52a73 --- /dev/null +++ b/src/pmquery/pmmessage.sh.in @@ -0,0 +1,2 @@ +#!/bin/sh +exec PCP_BIN_DIR/pmquery -noprint "$@" diff --git a/src/pmquery/pmquery.cpp b/src/pmquery/pmquery.cpp new file mode 100644 index 0000000..8dcbbda --- /dev/null +++ b/src/pmquery/pmquery.cpp @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2014 Red Hat. + * Copyright (c) 2007, Aconex. All Rights Reserved. + * + * 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. + */ +#include "pmquery.h" + +#define max(a,b) ((a)>(b)?(a):(b)) +#define DEFAULT_EDIT_WIDTH 640 /* in units of pixels */ +#define DEFAULT_EDIT_HEIGHT 320 /* only for usesliderflag */ + +enum icontypes { + INFO_ICON, + ERROR_ICON, + QUESTION_ICON, + WARNING_ICON, + ARCHIVE_ICON, + HOST_ICON, +} iconic; + +static const char *title = "Query"; +static int timeout; +static int *statusi; +static const char **buttons; +static int buttoncount; +static const char *defaultbutton; +static char **messages; +static int messagecount; + +static void nomem() +{ + fputs("Insufficient memory\n", stderr); + exit(1); +} + +int PmQuery::setTimeout(char *string) +{ + char *endnum; + timeout = (int)strtol(string, &endnum, 10); + if (*endnum != '\0' || timeout <= 0) + return -1; + return 0; +} + +void PmQuery::setTitle(char *heading) +{ + title = heading; +} + +int PmQuery::messageCount() +{ + return messagecount; +} + +int PmQuery::buttonCount() +{ + return buttoncount; +} + +int PmQuery::setIcontype(char *string) +{ + if (strcmp(string, "info") == 0) + iconic = INFO_ICON; + else if (strcmp(string, "error") == 0 || + strcmp(string, "action") == 0 || + strcmp(string, "critical") == 0) + iconic = ERROR_ICON; + else if (strcmp(string, "question") == 0) + iconic = QUESTION_ICON; + else if (strcmp(string, "warning") == 0) + iconic = WARNING_ICON; + else if (strcmp(string, "archive") == 0) + iconic = ARCHIVE_ICON; + else if (strcmp(string, "host") == 0) + iconic = HOST_ICON; + else + return -1; + return 0; +} + +void PmQuery::addMessage(char *string) +{ + messages = (char **)realloc(messages, (messagecount+1) * sizeof(char *)); + if (!messages) + nomem(); + messages[messagecount++] = string; +} + +void PmQuery::addButton(const char *string, bool iamdefault, int status) +{ + buttons = (const char **)realloc(buttons, (buttoncount+1) * sizeof(char *)); + statusi = (int *)realloc(statusi, (buttoncount+1) * sizeof(int)); + if (!buttons) + nomem(); + if (iamdefault) + defaultbutton = string; + statusi[buttoncount] = status; + buttons[buttoncount++] = string; +} + +void PmQuery::addButtons(char *string) // comma-separated label:exitcode string +{ + char *n; + QString pairs(string); + static int next = 100; + + QStringList list = pairs.split(","); + for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) { + QString name = (*it).section(":", 0, 0); + QString code = (*it).section(":", 1, 1); + if (!name.isEmpty()) { + int sts = code.isEmpty() ? ++next : code.toInt(); + if ((n = strdup(name.toAscii().data())) == NULL) + nomem(); + addButton(n, FALSE, sts); + } + } +} + +void PmQuery::setDefaultButton(char *string) +{ + for (int i = 0; i < buttoncount; i++) + if (strcmp(buttons[i], string) == 0) + defaultbutton = buttons[i]; +} + +void PmQuery::buttonClicked() +{ + done(my.status); +} + +void PmQuery::timerEvent(QTimerEvent *) +{ + done(1); +} + +// Currently we set default edit size to hardcoded values, until +// better ways are found to interact with any geometry requests. +// Note: the +4 pixels for height ensure the auto-scroll does not +// kick in, seems to be required. + +PmQuery::PmQuery(bool inputflag, bool printflag, bool noframeflag, + bool nosliderflag, bool usesliderflag, bool exclusiveflag) + : QDialog() +{ + QHBoxLayout *hboxLayout; + QVBoxLayout *vboxLayout; + QSpacerItem *spacerItem; + QSpacerItem *spacerItem1; + QVBoxLayout *vboxLayout1; + QHBoxLayout *hboxLayout1; + QSpacerItem *spacerItem2; + + QString filename; + if (iconic == HOST_ICON) + filename = tr(":images/dialog-host.png"); + else if (iconic == ERROR_ICON) + filename = tr(":images/dialog-error.png"); + else if (iconic == WARNING_ICON) + filename = tr(":images/dialog-warning.png"); + else if (iconic == ARCHIVE_ICON) + filename = tr(":images/dialog-archive.png"); + else if (iconic == QUESTION_ICON) + filename = tr(":images/dialog-question.png"); + else // (iconic == INFO_ICON) + filename = tr(":images/dialog-information.png"); + + QIcon icon(filename); + QPixmap pixmap(filename); + setWindowIcon(icon); + setWindowTitle(tr(title)); + + QGridLayout *gridLayout = new QGridLayout(this); + gridLayout->setSpacing(6); + gridLayout->setMargin(9); + hboxLayout = new QHBoxLayout(); + hboxLayout->setSpacing(6); + hboxLayout->setMargin(0); + vboxLayout = new QVBoxLayout(); + vboxLayout->setSpacing(6); + vboxLayout->setMargin(0); + spacerItem = new QSpacerItem(20, 2, QSizePolicy::Minimum, + QSizePolicy::Expanding); + + vboxLayout->addItem(spacerItem); + + QLabel *imageLabel = new QLabel(this); + imageLabel->setPixmap(pixmap); + + vboxLayout->addWidget(imageLabel); + + spacerItem1 = new QSpacerItem(20, 20, QSizePolicy::Minimum, + QSizePolicy::Expanding); + + vboxLayout->addItem(spacerItem1); + hboxLayout->addLayout(vboxLayout); + vboxLayout1 = new QVBoxLayout(); + vboxLayout1->setSpacing(6); + vboxLayout1->setMargin(0); + + int height; + int width = DEFAULT_EDIT_WIDTH; + + QLineEdit* lineEdit = NULL; + QTextEdit* textEdit = NULL; + if (inputflag && messagecount <= 1) { + lineEdit = new QLineEdit(this); + if (messagecount == 1) + lineEdit->setText(tr(messages[0])); + height = lineEdit->font().pointSize() + 4; + if (height < 0) + height = lineEdit->font().pixelSize() + 4; + if (height < 0) + height = lineEdit->heightForWidth(width) + 4; + lineEdit->setSizePolicy(QSizePolicy::MinimumExpanding, + QSizePolicy::Fixed); + lineEdit->setMinimumSize(QSize(width, height)); + lineEdit->setGeometry(QRect(0, 0, width, height)); + vboxLayout1->addWidget(lineEdit); + } + else { + QFont fixed("monospace"); + fixed.setStyleHint(QFont::TypeWriter); + + textEdit = new QTextEdit(this); + textEdit->setFont(fixed); + textEdit->setLineWrapMode(QTextEdit::FixedColumnWidth); + textEdit->setLineWrapColumnOrWidth(80); + textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + if (nosliderflag) + textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + else if (usesliderflag) + textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + else + textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + for (int m = 0; m < messagecount; m++) + textEdit->append(tr(messages[m])); + if (inputflag) + textEdit->setReadOnly(FALSE); + else { + textEdit->setLineWidth(1); + textEdit->setFrameStyle(noframeflag ? QFrame::NoFrame : + QFrame::Box | QFrame::Sunken); + textEdit->setReadOnly(TRUE); + } + if (usesliderflag) + height = DEFAULT_EDIT_HEIGHT; + else { + height = textEdit->font().pointSize() + 4; + if (height < 0) + height = textEdit->font().pixelSize() + 4; + if (height < 0) + height = textEdit->heightForWidth(width) + 4; + height *= messagecount; + } + textEdit->setMinimumSize(QSize(width, height)); + textEdit->setSizePolicy(QSizePolicy::MinimumExpanding, + QSizePolicy::MinimumExpanding); + textEdit->moveCursor(QTextCursor::Start); + textEdit->ensureCursorVisible(); + vboxLayout1->addWidget(textEdit); + } + + hboxLayout1 = new QHBoxLayout(); + hboxLayout1->setSpacing(6); + hboxLayout1->setMargin(0); + spacerItem2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, + QSizePolicy::Minimum); + hboxLayout1->addItem(spacerItem2); + + for (int i = 0; i < buttoncount; i++) { + QueryButton *button = new QueryButton(printflag, this); + button->setMinimumSize(QSize(72, 32)); + button->setDefault(buttons[i] == defaultbutton); + button->setQuery(this); + button->setText(tr(buttons[i])); + button->setStatus(statusi[i]); + if (inputflag && buttons[i] == defaultbutton) { + if (textEdit) + button->setEditor(textEdit); + else if (lineEdit) { + button->setEditor(lineEdit); + if (buttons[i] == defaultbutton) + connect(lineEdit, SIGNAL(returnPressed()), + button, SLOT(click())); + } + } + connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked())); + hboxLayout1->addWidget(button); + } + + vboxLayout1->addLayout(hboxLayout1); + hboxLayout->addLayout(vboxLayout1); + gridLayout->addLayout(hboxLayout, 0, 0, 1, 1); + gridLayout->setSizeConstraint(QLayout::SetFixedSize); + + if (inputflag && messagecount <= 1) + resize(QSize(320, 83)); + else + resize(QSize(320, 132)); + + if (timeout) + startTimer(timeout * 1000); + + if (exclusiveflag) + setWindowModality(Qt::WindowModal); +} diff --git a/src/pmquery/pmquery.h b/src/pmquery/pmquery.h new file mode 100644 index 0000000..e85fd14 --- /dev/null +++ b/src/pmquery/pmquery.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2007, Aconex. All Rights Reserved. + * + * 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. + */ +#ifndef KMQUERY_H +#define KMQUERY_H + +#include <QtCore/QVariant> +#include <QtCore/QTimerEvent> + +#include <QtGui/QAction> +#include <QtGui/QApplication> +#include <QtGui/QButtonGroup> +#include <QtGui/QDialog> +#include <QtGui/QGridLayout> +#include <QtGui/QHBoxLayout> +#include <QtGui/QLabel> +#include <QtGui/QLineEdit> +#include <QtGui/QTextEdit> +#include <QtGui/QPushButton> +#include <QtGui/QSpacerItem> +#include <QtGui/QVBoxLayout> +#include <QtGui/QWidget> + +#include <cstdio> + +class PmQuery : public QDialog +{ + Q_OBJECT +public: + PmQuery(bool inputflag, bool printflag, bool noframeflag, + bool nosliderflag, bool usesliderflag, bool exclusiveflag); + void setStatus(int status) { my.status = status; } + + static void setTitle(char *string); + static int setTimeout(char *string); + static int setIcontype(char *string); + + static int messageCount(); + static void addMessage(char *string); + + static int buttonCount(); + static void addButton(const char *string, bool iamdefault, int exitstatus); + static void addButtons(char *stringlist); + static void setDefaultButton(char *string); + +public slots: + void buttonClicked(); + +protected: + void timerEvent(QTimerEvent *); + +private: + struct { + int status; + } my; +}; + +class QueryButton : public QPushButton +{ + Q_OBJECT +public: + QueryButton(bool out, QWidget *p) : QPushButton(NULL, p) + { + my.s = 0; + my.k = NULL; + my.l = NULL; + my.t = NULL; + if (out) + connect(this, SIGNAL(clicked()), this, SLOT(print())); + else + connect(this, SIGNAL(clicked()), this, SLOT(noprint())); + } + void setQuery(PmQuery *dialog) { my.k = dialog; } + void setStatus(int status) { my.s = status; } + void setEditor(QLineEdit *editor) { my.l = editor; } + void setEditor(QTextEdit *editor) { my.t = editor; } + +public slots: + void print() + { + noprint(); puts(my.l ? my.l->text().toAscii().data() : (my.t? + my.t->toPlainText().toAscii().data() : text().toAscii().data())); + } + void noprint() { my.k->setStatus(my.s); } + +private: + struct { + int s; + PmQuery *k; + QLineEdit *l; + QTextEdit *t; + } my; +}; + +#endif // KMQUERY_H diff --git a/src/pmquery/pmquery.info.in b/src/pmquery/pmquery.info.in new file mode 100644 index 0000000..a3bb88f --- /dev/null +++ b/src/pmquery/pmquery.info.in @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> +<plist version="0.9"> +<dict> + <key>CFBundleIconFile</key> + <string>pmquery.icns</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleGetInfoString</key> + <string>PACKAGE_VERSION</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleExecutable</key> + <string>pmquery</string> + <key>CFBundleIdentifier</key> + <string>com.aconex.pmquery</string> +</dict> +</plist> diff --git a/src/pmquery/pmquery.pro b/src/pmquery/pmquery.pro new file mode 100644 index 0000000..6a4293f --- /dev/null +++ b/src/pmquery/pmquery.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +LANGUAGE = C++ +HEADERS = pmquery.h +SOURCES = pmquery.cpp main.cpp +ICON = pmquery.icns +RESOURCES = pmquery.qrc +CONFIG += qt warn_on +release:DESTDIR = build/debug +debug:DESTDIR = build/release diff --git a/src/pmquery/pmquery.qrc b/src/pmquery/pmquery.qrc new file mode 100644 index 0000000..39164cc --- /dev/null +++ b/src/pmquery/pmquery.qrc @@ -0,0 +1,10 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>images/dialog-archive.png</file> + <file>images/dialog-error.png</file> + <file>images/dialog-host.png</file> + <file>images/dialog-information.png</file> + <file>images/dialog-question.png</file> + <file>images/dialog-warning.png</file> +</qresource> +</RCC> diff --git a/src/pmquery/pmquery.sh.in b/src/pmquery/pmquery.sh.in new file mode 100644 index 0000000..aaf8351 --- /dev/null +++ b/src/pmquery/pmquery.sh.in @@ -0,0 +1,2 @@ +#!/bin/sh +exec PCP_BIN_DIR/pmquery "$@" |