Skip to content

Commit

Permalink
Merge pull request #218 from YoshiMan/master
Browse files Browse the repository at this point in the history
added a copy button for each line to paste the content into the clipboard, "pass init -- path=" command with right path-parameter, lupdate qtpass.pro
  • Loading branch information
annejan authored Nov 17, 2016
2 parents 8569f83 + 24a2794 commit 3f2b18a
Show file tree
Hide file tree
Showing 28 changed files with 1,859 additions and 1,658 deletions.
145 changes: 72 additions & 73 deletions localization/localization_ar_MA.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_cs_CZ.ts

Large diffs are not rendered by default.

154 changes: 84 additions & 70 deletions localization/localization_de_DE.ts

Large diffs are not rendered by default.

154 changes: 84 additions & 70 deletions localization/localization_de_LU.ts

Large diffs are not rendered by default.

141 changes: 70 additions & 71 deletions localization/localization_el_GR.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_en_GB.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_en_US.ts

Large diffs are not rendered by default.

145 changes: 72 additions & 73 deletions localization/localization_es_ES.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_fr_BE.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_fr_FR.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_fr_LU.ts

Large diffs are not rendered by default.

145 changes: 72 additions & 73 deletions localization/localization_gl_ES.ts

Large diffs are not rendered by default.

145 changes: 72 additions & 73 deletions localization/localization_he_IL.ts

Large diffs are not rendered by default.

145 changes: 72 additions & 73 deletions localization/localization_hu_HU.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_it_IT.ts

Large diffs are not rendered by default.

139 changes: 69 additions & 70 deletions localization/localization_lb_LU.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_nl_BE.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_nl_NL.ts

Large diffs are not rendered by default.

145 changes: 72 additions & 73 deletions localization/localization_pl_PL.ts

Large diffs are not rendered by default.

154 changes: 84 additions & 70 deletions localization/localization_ru_RU.ts

Large diffs are not rendered by default.

145 changes: 72 additions & 73 deletions localization/localization_sv_SE.ts

Large diffs are not rendered by default.

150 changes: 82 additions & 68 deletions localization/localization_zh_CN.ts

Large diffs are not rendered by default.

135 changes: 67 additions & 68 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QQueue>
#include <QTextCodec>
#include <QTimer>

#ifdef Q_OS_WIN
#define WIN32_LEAN_AND_MEAN /*_KILLING_MACHINE*/
#define WIN32_EXTRA_LEAN
Expand All @@ -22,6 +23,7 @@
#include "ui_mainwindow.h"
#include "usersdialog.h"
#include "util.h"
#include "qpushbuttonwithclipboard.h"

/**
* @brief MainWindow::MainWindow handles all of the main functionality and also
Expand Down Expand Up @@ -50,8 +52,7 @@ MainWindow::MainWindow(QWidget *parent)
// no working config
QApplication::quit();
}
ui->copyPasswordButton->setEnabled(false);
setClippedPassword("");
clippedText="";
QtPass = NULL;
QTimer::singleShot(10, this, SLOT(focusInput()));

Expand Down Expand Up @@ -682,7 +683,7 @@ QString MainWindow::getFile(const QModelIndex &index, bool forPass) {
void MainWindow::on_treeView_clicked(const QModelIndex &index) {
currentDir = getDir(ui->treeView->currentIndex(), false);
lastDecrypt = "Could not decrypt";
setClippedPassword("");
clippedText="";
QString file = getFile(index, usePass);
if (!file.isEmpty()) {
currentAction = GPG;
Expand Down Expand Up @@ -737,7 +738,7 @@ void MainWindow::executePassGitInit() {
if (usePass)
executePass("git init");
else
executeWrapper("git", "init \"" + passStore + '"');
executeWrapper(gitExecutable, "init \"" + passStore + '"');
}

/**
Expand Down Expand Up @@ -801,11 +802,12 @@ void MainWindow::readyRead(bool finished = false) {
if (finished && currentAction == GPG) {
lastDecrypt = output;
QStringList tokens = output.split("\n");
QString password = tokens.at(0);

if (useClipboard != CLIPBOARD_NEVER && !output.isEmpty()) {
setClippedPassword(tokens[0]);
clippedText=tokens[0];
if (useClipboard == CLIPBOARD_ALWAYS)
copyPasswordToClipboard();
copyTextToClipboard(tokens[0]);
if (useAutoclearPanel) {
QTimer::singleShot(1000 * autoclearPanelSeconds, this,
SLOT(clearPanel()));
Expand All @@ -819,46 +821,40 @@ void MainWindow::readyRead(bool finished = false) {
}

if (useTemplate && !hideContent) {
while (ui->formLayout->count() > 0) {
QLayoutItem *item = ui->formLayout->takeAt(0);
while (ui->gridLayout->count() > 0) {
QLayoutItem *item = ui->gridLayout->takeAt(0);
delete item->widget();
delete item;
}
QLineEdit *pass = new QLineEdit();
pass->setText(tokens[0]);
tokens.pop_front();
if (hidePassword)
pass->setEchoMode(QLineEdit::Password);
pass->setReadOnly(true);
ui->formLayout->addRow(pass);

for (int j = 0; j < tokens.length(); ++j) {
QStringList remainingTokens;
for (int j = 1; j < tokens.length(); ++j) {
QString token = tokens.at(j);
if (token.contains(':')) {
int colon = token.indexOf(':');
QString field = token.left(colon);
if (templateAllFields || passTemplate.contains(field)) {
QString value = token.right(token.length() - colon - 1);
if (!passTemplate.contains(field) && value.startsWith("//"))
if (!passTemplate.contains(field) && value.startsWith("//")){
continue; // colon is probably from a url
QLineEdit *line = new QLineEdit();
line->setObjectName(field);
line->setText(value);
line->setReadOnly(true);
ui->formLayout->addRow(new QLabel(field), line);
tokens.removeAt(j);
--j; // tokens.length() also got shortened by the remove..
}
addToGridLayout(j, field, value);
}
}else{
remainingTokens.append(token);
}
}
if (ui->formLayout->count() == 0)
if (ui->gridLayout->count() == 0)
ui->verticalLayoutPassword->setSpacing(0);
else
ui->verticalLayoutPassword->setSpacing(6);
output = tokens.join("\n");
output = remainingTokens.join("\n");
} else {
clearTemplateWidgets();
}
if (!hideContent){
// now set the password. If we set it earlier, the layout will be cleared
addToGridLayout(0, tr("Password"), password);
}
if (useAutoclearPanel) {
autoclearPass = output;
autoclearTimer = new QTimer(this);
Expand Down Expand Up @@ -906,7 +902,8 @@ void MainWindow::readyRead(bool finished = false) {
*/
void MainWindow::clearClipboard() {
QClipboard *clipboard = QApplication::clipboard();
if (clipboard->text() == getClippedPassword()) {
QString clippedText = clipboard->text();
if (clippedText == clippedText) {
clipboard->clear();
ui->statusBar->showMessage(tr("Clipboard cleared"), 3000);
} else {
Expand All @@ -918,8 +915,8 @@ void MainWindow::clearClipboard() {
* @brief MainWindow::clearPanel hide the information from shoulder surfers
*/
void MainWindow::clearPanel() {
while (ui->formLayout->count() > 0) {
QLayoutItem *item = ui->formLayout->takeAt(0);
while (ui->gridLayout->count() > 0) {
QLayoutItem *item = ui->gridLayout->takeAt(0);
delete item->widget();
delete item;
}
Expand Down Expand Up @@ -1472,7 +1469,11 @@ void MainWindow::on_usersButton_clicked() {
gpgIds += user.key_id + " ";
}
}
executePass("init --path=" + dir + " " + gpgIds);
// remove the passStore directory otherwise,
// pass would create a passStore/passStore/dir
// but you want passStore/dir
QString dirWithoutPassdir=dir.remove(0,passStore.size());
executePass("init --path=" + dirWithoutPassdir + " " + gpgIds);
} else {
QString gpgIdFile = dir + ".gpg-id";
QFile gpgId(gpgIdFile);
Expand Down Expand Up @@ -1751,12 +1752,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event) {
}
}

/**
* @brief MainWindow::on_copyPasswordButton_clicked just a launcher for
* MainWindow::copyPasswordToClipboard()
*/
void MainWindow::on_copyPasswordButton_clicked() { copyPasswordToClipboard(); }

/**
* @brief MainWindow::showContextMenu show us the (file or folder) context menu
* @param pos
Expand Down Expand Up @@ -1816,15 +1811,6 @@ void MainWindow::showContextMenu(const QPoint &pos) {
*/
void MainWindow::showBrowserContextMenu(const QPoint &pos) {
QMenu *contextMenu = ui->textBrowser->createStandardContextMenu(pos);

if (useClipboard != CLIPBOARD_NEVER) {
contextMenu->addSeparator();
QAction *copyItem = contextMenu->addAction(tr("Copy Password"));
if (getClippedPassword().length() == 0)
copyItem->setEnabled(false);
connect(copyItem, SIGNAL(triggered()), this,
SLOT(copyPasswordToClipboard()));
}
QPoint globalPos = ui->textBrowser->viewport()->mapToGlobal(pos);

contextMenu->exec(globalPos);
Expand Down Expand Up @@ -1942,42 +1928,35 @@ void MainWindow::waitFor(int seconds) {
* the UI
*/
void MainWindow::clearTemplateWidgets() {
while (ui->formLayout->count() > 0) {
QLayoutItem *item = ui->formLayout->takeAt(0);
while (ui->gridLayout->count() > 0) {
QLayoutItem *item = ui->gridLayout->takeAt(0);
delete item->widget();
delete item;
}
ui->verticalLayoutPassword->setSpacing(0);
}

/**
* @brief Mainwindow::copyPasswordToClipboard - copy the clipped password (if
* not "") to the clipboard
* @brief Mainwindow::copyTextByButtonClick - copy the text to the clipboard
* @param checked
* no use, we need it, because of QPushButtonWithClipboard::clicked function
*/
void MainWindow::copyPasswordToClipboard() {
if (clippedPass.length() > 0) {
void MainWindow::copyTextByButtonClick(bool checked)
{
QString textToCopy = ((QPushButtonWithClipboard*)sender())->getTextToCopy();
copyTextToClipboard(textToCopy);
}

void MainWindow::copyTextToClipboard(const QString &text) {
QClipboard *clip = QApplication::clipboard();
clip->setText(clippedPass);
ui->statusBar->showMessage(tr("Password copied to clipboard"), 3000);
clip->setText(text);
clippedText=text;
ui->statusBar->showMessage(tr("Copied to clipboard"), 3000);
if (useAutoclear) {
QTimer::singleShot(1000 * autoclearSeconds, this, SLOT(clearClipboard()));
}
}
}

/**
* @brief Mainwindow::setClippedPassword - set the stored clipped password
*/
void MainWindow::setClippedPassword(const QString &pass) {
clippedPass = pass;
if (clippedPass.length() == 0)
ui->copyPasswordButton->setEnabled(false);
else
ui->copyPasswordButton->setEnabled(true);
}

const QString &MainWindow::getClippedPassword() { return clippedPass; }

/**
* @brief MainWindow::reencryptPath reencrypt all files under the chosen
* directory
Expand Down Expand Up @@ -2074,3 +2053,23 @@ void MainWindow::reencryptPath(QString dir) {
on_pushButton_clicked();
enableUiElements(true);
}

void MainWindow::addToGridLayout(int position, const QString &field, const QString &value)
{
QString trimmedField = field.trimmed();
QString trimmedValue = value.trimmed();
QLineEdit *line = new QLineEdit();
line->setObjectName(trimmedField);
line->setText(trimmedValue);
line->setReadOnly(true);
// set the echo mode to password, if the field is "password"
if (hidePassword && trimmedField == tr("Password")){
line->setEchoMode(QLineEdit::Password);
}
QPushButtonWithClipboard *fieldLabel = new QPushButtonWithClipboard(trimmedValue, this);
connect(fieldLabel, SIGNAL(clicked()), this, SLOT(copyTextByButtonClick()));
// set into the layout
ui->gridLayout->addWidget(fieldLabel, position, 0);
ui->gridLayout->addWidget(new QLabel(trimmedField), position, 1);
ui->gridLayout->addWidget(line, position, 2);
}
10 changes: 5 additions & 5 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class MainWindow : public QMainWindow {
QString generatePassword(int length, clipBoardType selection);
void config();
void executePassGitInit();
void copyTextToClipboard(const QString &text);


/**
* @brief MainWindow::pwdConfig instance of passwordConfiguration.
Expand Down Expand Up @@ -146,13 +148,12 @@ private slots:
void on_usersButton_clicked();
void messageAvailable(QString message);
void on_profileBox_currentIndexChanged(QString);
void on_copyPasswordButton_clicked();
void showContextMenu(const QPoint &pos);
void showBrowserContextMenu(const QPoint &pos);
void addFolder();
void editPassword();
void focusInput();
void copyPasswordToClipboard();
void copyTextByButtonClick(bool checked = false);

private:
QAction *actionAddPassword;
Expand Down Expand Up @@ -185,7 +186,7 @@ private slots:
QString webDavUser;
QString webDavPassword;
QProcess fusedav;
QString clippedPass;
QString clippedText;
QString autoclearPass;
QTimer *autoclearTimer;
actionType currentAction;
Expand Down Expand Up @@ -237,9 +238,8 @@ private slots:
bool removeDir(const QString &dirName);
void waitFor(int seconds);
void clearTemplateWidgets();
void setClippedPassword(const QString &pass);
const QString &getClippedPassword();
void reencryptPath(QString dir);
void addToGridLayout(int position, const QString &field, const QString &value);
};

#endif // MAINWINDOW_H_
53 changes: 14 additions & 39 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>366</width>
<width>847</width>
<height>291</height>
</rect>
</property>
Expand Down Expand Up @@ -223,20 +223,18 @@
</spacer>
</item>
<item>
<widget class="QToolButton" name="copyPasswordButton">
<property name="toolTip">
<string>Copy Password</string>
</property>
<property name="text">
<string>Copy Password</string>
</property>
<property name="icon">
<iconset theme="edit-copy">
<normalon>:/icons/edit-copy.svg</normalon>
</iconset>
<widget class="QComboBox" name="profileBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
<property name="minimumSize">
<size>
<width>100</width>
<height>26</height>
</size>
</property>
</widget>
</item>
Expand All @@ -253,22 +251,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="profileBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>26</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -313,22 +295,15 @@
<number>0</number>
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</layout>
<layout class="QGridLayout" name="gridLayout"/>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser">
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Cantarell'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; font-weight:600; color:#333333;&quot;&gt;QtPass&lt;/span&gt;&lt;span style=&quot; font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;&quot;&gt; is a GUI for &lt;/span&gt;&lt;a href=&quot;https://www.passwordstore.org/&quot;&gt;&lt;span style=&quot; font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4; background-color:transparent;&quot;&gt;pass&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;&quot;&gt;, the standard unix password manager.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;&quot;&gt;&lt;br /&gt;Please report any &lt;/span&gt;&lt;a href=&quot;https://github.com/IJHack/qtpass/issues&quot;&gt;&lt;span style=&quot; font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4;&quot;&gt;issues&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;&quot;&gt; you might have with this software.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;a href=&quot;https://qtpass.org/&quot;&gt;&lt;span style=&quot; font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4; background-color:transparent;&quot;&gt;Documentation&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
Expand Down
Loading

0 comments on commit 3f2b18a

Please sign in to comment.