Skip to content

Commit

Permalink
coding style updated
Browse files Browse the repository at this point in the history
  • Loading branch information
tezeb committed Jan 3, 2017
1 parent 055a965 commit f20d251
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 107 deletions.
3 changes: 3 additions & 0 deletions qtpass.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ INSTALLS += target
DISTFILES += \
settingsToDelete.txt

RESOURCES += \
src/resources.qrc

142 changes: 69 additions & 73 deletions src/imitatepass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
ImitatePass::ImitatePass() {}


/**
* @brief ImitatePass::GitInit git init wrapper
*/
Expand All @@ -20,9 +19,7 @@ void ImitatePass::GitInit() {
/**
* @brief ImitatePass::GitPull git init wrapper
*/
void ImitatePass::GitPull() {
executeGit(GIT_PULL,{"pull"});
}
void ImitatePass::GitPull() { executeGit(GIT_PULL, {"pull"}); }

/**
* @brief ImitatePass::GitPull_b git pull wrapper
Expand All @@ -35,8 +32,8 @@ void ImitatePass::GitPull_b() {
* @brief ImitatePass::GitPush git init wrapper
*/
void ImitatePass::GitPush() {
if(QtPassSettings::isUseGit()){
executeGit(GIT_PUSH, {"push"});
if (QtPassSettings::isUseGit()) {
executeGit(GIT_PUSH, {"push"});
}
}

Expand Down Expand Up @@ -76,8 +73,7 @@ void ImitatePass::Insert(QString file, QString newValue, bool overwrite) {
if (overwrite)
args.append("--yes");
args.append("-");
executeGpg(PASS_INSERT, args,
newValue);
executeGpg(PASS_INSERT, args, newValue);
if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit()) {
// TODO(bezet) why not?
if (!overwrite)
Expand Down Expand Up @@ -299,78 +295,78 @@ void ImitatePass::reencryptPath(QString dir) {
emit endReencryptPath();
}

void ImitatePass::Move(const QString src, const QString dest, const bool force)
{
QFileInfo destFileInfo(dest);
if (QtPassSettings::isUseGit()) {
QStringList args;
args << "mv";
if(force){
args << "-f";
}
args << src;
args << dest;
executeGit(GIT_MOVE, args);
void ImitatePass::Move(const QString src, const QString dest,
const bool force) {
QFileInfo destFileInfo(dest);
if (QtPassSettings::isUseGit()) {
QStringList args;
args << "mv";
if (force) {
args << "-f";
}
args << src;
args << dest;
executeGit(GIT_MOVE, args);

QString message=QString("moved from %1 to %2 using QTPass.");
message= message.arg(src).arg(dest);
GitCommit("", message);
if(QtPassSettings::isAutoPush()){
GitPush();
}
QString message = QString("moved from %1 to %2 using QTPass.");
message = message.arg(src).arg(dest);
GitCommit("", message);
if (QtPassSettings::isAutoPush()) {
GitPush();
}

} else {
QDir qDir;
QFileInfo srcFileInfo(src);
QString destCopy = dest;
if(srcFileInfo.isFile() && destFileInfo.isDir()){
destCopy = destFileInfo.absoluteFilePath() + QDir::separator() + srcFileInfo.fileName();
}
if(force){
qDir.remove(destCopy);
}
qDir.rename(src, destCopy);
} else {
QDir qDir;
QFileInfo srcFileInfo(src);
QString destCopy = dest;
if (srcFileInfo.isFile() && destFileInfo.isDir()) {
destCopy = destFileInfo.absoluteFilePath() + QDir::separator() +
srcFileInfo.fileName();
}
// reecrypt all files under the new folder
if(destFileInfo.isDir()){
reencryptPath(destFileInfo.absoluteFilePath());
}else if(destFileInfo.isFile()){
reencryptPath(destFileInfo.dir().path());
if (force) {
qDir.remove(destCopy);
}
qDir.rename(src, destCopy);
}
// reecrypt all files under the new folder
if (destFileInfo.isDir()) {
reencryptPath(destFileInfo.absoluteFilePath());
} else if (destFileInfo.isFile()) {
reencryptPath(destFileInfo.dir().path());
}
}

void ImitatePass::Copy(const QString src, const QString dest,
const bool force) {
QFileInfo destFileInfo(dest);
if (QtPassSettings::isUseGit()) {
QStringList args;
args << "cp";
if (force) {
args << "-f";
}
args << src;
args << dest;
executeGit(GIT_COPY, args);

void ImitatePass::Copy(const QString src, const QString dest, const bool force)
{
QFileInfo destFileInfo(dest);
if (QtPassSettings::isUseGit()) {
QStringList args;
args << "cp";
if(force){
args << "-f";
}
args << src;
args << dest;
executeGit(GIT_COPY, args);

QString message=QString("copied from %1 to %2 using QTPass.");
message= message.arg(src).arg(dest);
GitCommit("", message);
if(QtPassSettings::isAutoPush()){
GitPush();
}

} else {
QDir qDir;
if(force){
qDir.remove(dest);
}
QFile::copy(src, dest);
QString message = QString("copied from %1 to %2 using QTPass.");
message = message.arg(src).arg(dest);
GitCommit("", message);
if (QtPassSettings::isAutoPush()) {
GitPush();
}
// reecrypt all files under the new folder
if(destFileInfo.isDir()){
reencryptPath(destFileInfo.absoluteFilePath());
}else if(destFileInfo.isFile()){
reencryptPath(destFileInfo.dir().path());

} else {
QDir qDir;
if (force) {
qDir.remove(dest);
}
QFile::copy(src, dest);
}
// reecrypt all files under the new folder
if (destFileInfo.isDir()) {
reencryptPath(destFileInfo.absoluteFilePath());
} else if (destFileInfo.isFile()) {
reencryptPath(destFileInfo.dir().path());
}
}
4 changes: 2 additions & 2 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ p, li { white-space: pre-wrap; }
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/artwork/icon.ico</pixmap>
<pixmap resource="../resources.qrc">:/artwork/icon.ico</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
Expand Down Expand Up @@ -496,7 +496,7 @@ p, li { white-space: pre-wrap; }
<tabstop>profileBox</tabstop>
</tabstops>
<resources>
<include location="resources.qrc"/>
<include location="../resources.qrc"/>
</resources>
<connections/>
<slots>
Expand Down
59 changes: 27 additions & 32 deletions src/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ Pass::Pass() : wrapperRunning(false), env(QProcess::systemEnvironment()) {
connect(&exec, &Executor::starting, this, &Pass::startingExecuteWrapper);
}

void Pass::executeWrapper(int id, const QString &app,
const QStringList &args, bool readStdout,
bool readStderr) {
void Pass::executeWrapper(int id, const QString &app, const QStringList &args,
bool readStdout, bool readStderr) {
executeWrapper(id, app, args, QString(), readStdout, readStderr);
}

void Pass::executeWrapper(int id, const QString &app,
const QStringList &args, QString input,
bool readStdout, bool readStderr) {
void Pass::executeWrapper(int id, const QString &app, const QStringList &args,
QString input, bool readStdout, bool readStderr) {
QString d;
for (auto &i : args)
d += " " + i;
Expand All @@ -37,21 +35,21 @@ void Pass::executeWrapper(int id, const QString &app,
readStderr);
}

void Pass::init(){
#ifdef __APPLE__
// If it exists, add the gpgtools to PATH
if (QFile("/usr/local/MacGPG2/bin").exists())
env.replaceInStrings("PATH=", "PATH=/usr/local/MacGPG2/bin:");
// Add missing /usr/local/bin
if (env.filter("/usr/local/bin").isEmpty())
env.replaceInStrings("PATH=", "PATH=/usr/local/bin:");
#endif
void Pass::init() {
#ifdef __APPLE__
// If it exists, add the gpgtools to PATH
if (QFile("/usr/local/MacGPG2/bin").exists())
env.replaceInStrings("PATH=", "PATH=/usr/local/MacGPG2/bin:");
// Add missing /usr/local/bin
if (env.filter("/usr/local/bin").isEmpty())
env.replaceInStrings("PATH=", "PATH=/usr/local/bin:");
#endif

if (!QtPassSettings::getGpgHome().isEmpty()) {
QDir absHome(QtPassSettings::getGpgHome());
absHome.makeAbsolute();
env << "GNUPGHOME=" + absHome.path();
}
if (!QtPassSettings::getGpgHome().isEmpty()) {
QDir absHome(QtPassSettings::getGpgHome());
absHome.makeAbsolute();
env << "GNUPGHOME=" + absHome.path();
}
}

/**
Expand Down Expand Up @@ -281,29 +279,26 @@ QString Pass::getRecipientString(QString for_file, QString separator,
* @param args
*/
void Pass::executePass(int id, const QStringList &args, QString input,
bool readStdout ,bool readStderr)
{
executeWrapper(id, QtPassSettings::getPassExecutable(), args , input,
readStdout, readStderr);
bool readStdout, bool readStderr) {
executeWrapper(id, QtPassSettings::getPassExecutable(), args, input,
readStdout, readStderr);
}

/**
* @brief Pass::executeGpg easy wrapper for running gpg commands
* @param args
*/
void Pass::executeGpg(int id, const QStringList &args, QString input,
bool readStdout,bool readStderr)
{
executeWrapper(id, QtPassSettings::getGpgExecutable(), args, input,
readStdout, readStderr);
bool readStdout, bool readStderr) {
executeWrapper(id, QtPassSettings::getGpgExecutable(), args, input,
readStdout, readStderr);
}
/**
* @brief Pass::executeGit easy wrapper for running git commands
* @param args
*/
void Pass::executeGit(int id, const QStringList &args, QString input,
bool readStdout,bool readStderr)
{
executeWrapper(id, QtPassSettings::getGitExecutable(), args, input,
readStdout, readStderr);
bool readStdout, bool readStderr) {
executeWrapper(id, QtPassSettings::getGitExecutable(), args, input,
readStdout, readStderr);
}

0 comments on commit f20d251

Please sign in to comment.