Skip to content

Commit

Permalink
Merge pull request #44 from IJHack/develop
Browse files Browse the repository at this point in the history
SingleApplication per user and leading newline removed from output
  • Loading branch information
annejan committed May 6, 2015
2 parents 8e87bc3 + 3230383 commit 40d10d8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 40 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ On most systems all you need is:

On MacOsX:
`qmake && make && macdeployqt QtPass.app -dmg`
* Currently seems to only work with MacGPG2

Currently seems to only work with MacGPG2
On some systems there are issues with qt4 and qt5 being installed at the same time.
An easy fix is regenerating the Makefile with: `make clean && rm Makefile && qmake -qt5` or if qmake is ambiguous: `qmake-qt5`

Further reading
---------------
Expand Down
29 changes: 15 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

int main(int argc, char *argv[])
{
QString text = "";
for (int i = 1; i < argc; ++i) {
if (i > 1) {
text += " ";
}
text += argv[i];
}
#if SINGLE_APP
SingleApplication app(argc, argv, "ijhackQtPass");
QString name = qgetenv("USER");
if (name.isEmpty())
name = qgetenv("USERNAME");
//qDebug() << name;
SingleApplication app(argc, argv, name + "QtPass");
if (app.isRunning()) {
if (argc == 1 ) {
app.sendMessage("show");
} else if (argc >= 2) {
QString text = "";
for (int i = 1; i < argc; ++i) {
text += argv[i];
if (argc >= (i - 2)) {
text += " ";
}
app.sendMessage(text);
}
}
app.sendMessage(text);
return 0;
}
#else
QApplication app(argc, argv);
#endif

QCoreApplication::setOrganizationName("IJHack");
QCoreApplication::setOrganizationDomain("ijhack.org");
QCoreApplication::setApplicationName("QtPass");
Expand All @@ -42,6 +42,7 @@ int main(int argc, char *argv[])
app.setWindowIcon(QIcon(":artwork/icon.png"));
w.setApp(&app);
w.checkConfig();
w.setText(text);
w.show();

return app.exec();
Expand Down
62 changes: 37 additions & 25 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,31 +381,31 @@ void MainWindow::executeWrapper(QString app, QString args, QString input) {
* @brief MainWindow::readyRead
*/
void MainWindow::readyRead(bool finished = false) {
QString output;
QString output = "";
if (currentAction != GPG_INTERNAL) {
output = process->readAllStandardOutput();
if (finished && currentAction == GPG) {
lastDecrypt = output;
if (useClipboard) {
QClipboard *clip = QApplication::clipboard();
QStringList tokens = output.split("\n");
clip->setText(tokens[0]);
ui->statusBar->showMessage(tr("Password copied to clipboard"), 3000);
if (useAutoclear) {
clippedPass = tokens[0];
QTimer::singleShot(1000*autoclearSeconds, this, SLOT(clearClipboard()));
}
if (hidePassword) {
tokens.pop_front();
output = tokens.join("\n");
}
if (hideContent) {
output = tr("Content hidden");
output = process->readAllStandardOutput();
if (finished && currentAction == GPG) {
lastDecrypt = output;
if (useClipboard) {
QClipboard *clip = QApplication::clipboard();
QStringList tokens = output.split("\n");
clip->setText(tokens[0]);
ui->statusBar->showMessage(tr("Password copied to clipboard"), 3000);
if (useAutoclear) {
clippedPass = tokens[0];
QTimer::singleShot(1000*autoclearSeconds, this, SLOT(clearClipboard()));
}
if (hidePassword) {
tokens.pop_front();
output = tokens.join("\n");
}
if (hideContent) {
output = "<font color=\"blue\">" + tr("Content hidden") + "</font><br />";
}
}
}
}
output.replace(QRegExp("<"), "&lt;");
output.replace(QRegExp(">"), "&gt;");
output.replace(QRegExp("<"), "&lt;");
output.replace(QRegExp(">"), "&gt;");
}

QString error = process->readAllStandardError();
Expand All @@ -414,8 +414,11 @@ void MainWindow::readyRead(bool finished = false) {
}

output.replace(QRegExp("((http|https|ftp)\\://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\\-\\._\\?\\,\\'/\\\\+&amp;%\\$#\\=~])*)"), "<a href=\"\\1\">\\1</a>");
output.replace(QRegExp("\n"), "<br />");
ui->textBrowser->setHtml(ui->textBrowser->toHtml() + output);
output.replace(QRegExp("\n )"), "<br />");
if (ui->textBrowser->toPlainText() != "") {
output = ui->textBrowser->toHtml() + output;
}
ui->textBrowser->setHtml(output);
}

/**
Expand Down Expand Up @@ -853,7 +856,7 @@ void MainWindow::setApp(SingleApplication *app)
*/
void MainWindow::messageAvailable(QString message)
{
if (message == "show") {
if (message == "") {
ui->lineEdit->selectAll();
ui->lineEdit->setFocus();
} else {
Expand All @@ -864,3 +867,12 @@ void MainWindow::messageAvailable(QString message)
show();
raise();
}

/**
* @brief MainWindow::setText
* @param message
*/
void MainWindow::setText(QString text)
{
ui->lineEdit->setText(text);
}
1 change: 1 addition & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum actionType { GPG, GIT, EDIT, DELETE, GPG_INTERNAL };
void setGpgExecutable(QString);
void checkConfig();
void setApp(SingleApplication* app);
void setText(QString);

private slots:
void on_updateButton_clicked();
Expand Down

0 comments on commit 40d10d8

Please sign in to comment.