Skip to content

Commit

Permalink
- Altered notebook view to account for different icons
Browse files Browse the repository at this point in the history
- Added the ability to delete & rename accounts.
- Added a basic error message & retry count in the sync thread.
- Set line numbers on all log messages.
  • Loading branch information
baumgarr committed Feb 24, 2013
1 parent f3ec712 commit 4c500a5
Show file tree
Hide file tree
Showing 25 changed files with 543 additions and 55 deletions.
133 changes: 125 additions & 8 deletions Makefile

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions NixNote2.pro
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ SOURCES += main.cpp\
dialog/preferences/syncpreferences.cpp \
dialog/preferences/appearancepreferences.cpp \
settings/accountsmanager.cpp \
dialog/adduseraccountdialog.cpp
dialog/adduseraccountdialog.cpp \
dialog/accountmaintenancedialog.cpp
# thrift/TApplicationException.cpp \
# thrift/Thrift.cpp \
# thrift/VirtualProfiling.cpp \
Expand Down Expand Up @@ -304,7 +305,8 @@ HEADERS += nixnote.h \
dialog/preferences/syncpreferences.h \
dialog/preferences/appearancepreferences.h \
settings/accountsmanager.h \
dialog/adduseraccountdialog.h
dialog/adduseraccountdialog.h \
dialog/accountmaintenancedialog.h
# thrift/TApplicationException.h \
# thrift/Thrift.h \
# thrift/TLogging.h \
Expand Down
8 changes: 8 additions & 0 deletions application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ bool Application::notify(QObject *receiver_, QEvent *event_)
}
catch (std::exception &ex)
{
QLOG_ERROR() << "**********************************************************";
QLOG_ERROR() << "**********************************************************";
QLOG_ERROR() << "**********************************************************";
QLOG_ERROR() << "**********************************************************";
QLOG_ERROR() << "**********************************************************";
QLOG_ERROR() << "**********************************************************";
QLOG_ERROR() << "**********************************************************";
QLOG_ERROR() << "std::exception was caught: " << ex.what();
emit (stdException(QString::fromStdString(ex.what())));
}

return false;
Expand Down
1 change: 1 addition & 0 deletions application.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Application : public QApplication
bool notify(QObject *receiver_, QEvent *event_);

signals:
void stdException(QString msg);

public slots:

Expand Down
1 change: 1 addition & 0 deletions communication/communicationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ bool CommunicationManager::getUserInfo(User &user) {
QLOG_ERROR() << "EDAMSystemException:" << QString::fromStdString(e.message) << endl;
return false;
}

return true;
}

Expand Down
190 changes: 190 additions & 0 deletions dialog/accountmaintenancedialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#include "accountmaintenancedialog.h"
#include <QSpacerItem>
#include <QMessageBox>
#include <QList>
#include "global.h"
#include "dialog/adduseraccountdialog.h"

extern Global global;

AccountMaintenanceDialog::AccountMaintenanceDialog(NMainMenuBar *menubar, QWidget *parent) :
QDialog(parent)
{
this->parent = parent;
this->menuBar = menubar;
okButton = new QPushButton(tr("Ok"), this);
closeButton = new QPushButton(tr("Close"),this);
addButton = new QPushButton(tr("Add"),this);
renameButton = new QPushButton(tr("Rename"));
deleteButton = new QPushButton(tr("Delete"));
nameList = new QListWidget(this);
buttonLayout1 = new QVBoxLayout();
buttonLayout2 = new QHBoxLayout();
displayLayout = new QHBoxLayout();
mainLayout = new QVBoxLayout();

displayLayout->addWidget(nameList);
displayLayout->addLayout(buttonLayout1);
buttonLayout1->addWidget(addButton);
buttonLayout1->addWidget(renameButton);
buttonLayout1->addWidget(deleteButton);
buttonLayout1->addSpacerItem(new QSpacerItem(0,0,QSizePolicy::Minimum, QSizePolicy::Maximum));
buttonLayout1->setStretch(4,100);
mainLayout->addLayout(displayLayout);
mainLayout->addLayout(buttonLayout2);

buttonLayout2->addSpacerItem(new QSpacerItem(0,0,QSizePolicy::Maximum, QSizePolicy::Minimum));
buttonLayout2->addWidget(okButton);
buttonLayout2->addWidget(closeButton);
buttonLayout2->addSpacerItem(new QSpacerItem(0,0,QSizePolicy::Maximum, QSizePolicy::Minimum));
buttonLayout2->setStretch(0,100);
buttonLayout2->setStretch(3,100);
this->setLayout(mainLayout);
this->setWindowTitle(tr("User Accountt Maintenance"));

connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
connect(addButton, SIGNAL(clicked()), this, SLOT(addAccount()));
connect(deleteButton,SIGNAL(clicked()), this, SLOT(deleteAccount()));
connect(renameButton, SIGNAL(clicked()), this, SLOT(renameAccount()));
this->loadData();
}



void AccountMaintenanceDialog::loadData() {
names.clear();
ids.clear();
nameList->clear();
deleteButton->setEnabled(false);

names = global.accountsManager->nameList();
ids = global.accountsManager->idList();
for (int i=0; i<names.size(); i++)
nameList->addItem(names[i]);

if (ids.size() >= 2) {
deleteButton->setEnabled(true);
}
nameList->sortItems();

}


void AccountMaintenanceDialog::deleteAccount() {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Question);
msgBox.setText(tr("Are you sure you want to delete this account?"));
msgBox.setWindowTitle(tr("Verify Delete"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec();
if (ret == QMessageBox::No)
return;
int id = -1;
QString name = nameList->selectedItems()[0]->text();
for (int i=0; i<names.size(); i++) {
if (names[i] == name) {
if (ids[i] == global.accountsManager->currentId) {
msgBox.setIcon(QMessageBox::Information);
msgBox.setText(tr("You cannot delete the active account."));
msgBox.setWindowTitle("Error deleting account");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
return;
}
global.accountsManager->removeId(ids[i]);
id = ids[i];
i=names.size();
}
}
loadData();
if (id>-1) {
for (int i=0; i<menuBar->userAccountActions.size(); i++) {
QAction *action = menuBar->userAccountActions[i];
if (action->data().toInt() == id) {
action = menuBar->userAccountActions.takeAt(i);
action->disconnect();
menuBar->removeAction(action);
delete action;
}
}
}
removeDir(global.fileManager.getHomeDirPath("")+QString("db-")+QString::number(id));
}

void AccountMaintenanceDialog::renameAccount() {
int id = -1;
bool activeId = false;
QString name = nameList->selectedItems()[0]->text();
QString newName;
for (int i=0; i<names.size(); i++) {
if (names[i] == name) {
if (ids[i] == global.accountsManager->currentId)
activeId = true;
else
activeId = false;
AddUserAccountDialog userDialog;
userDialog.newAccountName->setText(name);
userDialog.exec();
if (!userDialog.okPushed)
return;
newName = userDialog.newAccountName->text();
global.accountsManager->setName(newName, ids[i]);
id = ids[i];
i=names.size();
}
}
if (!activeId)
newName = tr("Switch to ") + newName;
if (id>-1) {
for (int i=0; i<menuBar->userAccountActions.size(); i++) {
QAction *action = menuBar->userAccountActions[i];
if (action->data().toInt() == id) {
action = menuBar->userAccountActions.at(i);
action->setText(newName);
}
}
}
loadData();
}


void AccountMaintenanceDialog::addAccount() {
AddUserAccountDialog dialog;
dialog.exec();
if (!dialog.okPushed)
return;
QString name = dialog.newAccountName->text().trimmed();
int newid = global.accountsManager->addId(-1, name);
QAction *newAction = new QAction(menuBar);
newAction->setText(tr("Switch to ") +name);
newAction->setCheckable(true);
newAction->setData(newid);
menuBar->addUserAccount(newAction);
connect(newAction, SIGNAL(triggered()), (NixNote*)parent, SLOT(switchUser()));
loadData();
}


bool AccountMaintenanceDialog:: removeDir(const QString & dirName) {
bool result;
QDir dir(dirName);

if (dir.exists(dirName)) {
Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
if (info.isDir()) {
result = removeDir(info.absoluteFilePath());
}
else {
result = QFile::remove(info.absoluteFilePath());
}

if (!result) {
return result;
}
}
result = dir.rmdir(dirName);
}
return result;
}
46 changes: 46 additions & 0 deletions dialog/accountmaintenancedialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef ACCOUNTMAINTENANCEDIALOG_H
#define ACCOUNTMAINTENANCEDIALOG_H

#include <QDialog>
#include <QListWidget>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include "gui/nmainmenubar.h"

class AccountMaintenanceDialog : public QDialog
{
Q_OBJECT
private:
NMainMenuBar *menuBar;
QPushButton *okButton;
QPushButton *closeButton;
QPushButton *addButton;
QPushButton *renameButton;
QPushButton *deleteButton;
QListWidget *nameList;
QVBoxLayout *buttonLayout1;
QHBoxLayout *buttonLayout2;
QHBoxLayout *displayLayout;
QVBoxLayout *mainLayout;
void loadData();
QList<QString> names;
QList<int> ids;
bool removeDir(const QString & dirName);
QWidget *parent;

public:
explicit AccountMaintenanceDialog(NMainMenuBar *menuBar, QWidget *parent = 0);

signals:

public slots:
void addAccount();
void deleteAccount();
void renameAccount();

};

#endif // ACCOUNTMAINTENANCEDIALOG_H
16 changes: 10 additions & 6 deletions dialog/notebookproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ NotebookProperties::NotebookProperties(QWidget *parent) :
QDialog(parent)
{
okPressed = false;
setWindowTitle(tr("Tag"));
setWindowIcon(QIcon(":tag.png"));
setWindowTitle(tr("Notebook"));
setWindowIcon(QIcon(":notebook_small.png"));
setLayout(&grid);

syncBox.setText(tr("Synchronized"));
Expand Down Expand Up @@ -75,16 +75,17 @@ void NotebookProperties::okButtonPressed() {
return;
}

// We have a new tag to add
// We have a new notebook to add
Notebook book;
book.name = name.text().trimmed().toStdString();
bool isSynchronized = syncBox.isChecked();
QUuid uuid;
QString g = uuid.createUuid().toString().replace("{","").replace("}","");
book.guid = g.toStdString();
book.__isset.name = true;
book.__isset.guid = true;
NotebookTable t;
t.add(0,book,true);
t.add(0,book,true, !isSynchronized);
close();
}

Expand All @@ -102,9 +103,12 @@ void NotebookProperties::setLid(qint32 lid) {
originalName = QString::fromStdString(book.name).trimmed();
name.setText(originalName);
syncBox.setEnabled(false);
bool local = table.isLocal(lid);
syncBox.setChecked(!local);
return;
}
this->lid = 0;
syncBox.setEnabled(true);
this->setWindowTitle(tr("Add Notebook"));
originalName = "";
}
Expand All @@ -116,8 +120,8 @@ void NotebookProperties::validateInput() {
return;
}
NotebookTable t;
QString tag = name.text().trimmed();
if (t.findByName(tag)>0 && name.text().trimmed() != originalName) {
QString notebook = name.text().trimmed();
if (t.findByName(notebook)>0 && name.text().trimmed() != originalName) {
ok.setEnabled(false);
return;
}
Expand Down
4 changes: 3 additions & 1 deletion global.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define GLOBAL_H

#include <QString>
#include "application.h"
#include <QSettings>

#include "logger/qslog.h"
Expand Down Expand Up @@ -80,7 +81,8 @@ class Global
int argc; // Initial argument count from the program start
char** argv; // List of arguments from the program start
FileManager fileManager;
AccountsManager *accountsManager;
AccountsManager *accountsManager;\
Application *application;
unsigned int cryptCounter;
QString attachmentNameDelimeter;
string username;
Expand Down
5 changes: 5 additions & 0 deletions gui/nmainmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ void NMainMenuBar::setupFileMenu() {
fileMenu->addAction(addUserAction);
connect(addUserAction, SIGNAL(triggered()), parent, SLOT(addAnotherUser()));

userMaintenanceAction = new QAction(tr("User Account Maintenance"),this);
userMaintenanceAction->setFont(font);
fileMenu->addAction(userMaintenanceAction);
connect(userMaintenanceAction, SIGNAL(triggered()), parent, SLOT(userMaintenance()));

fileMenu->addSeparator();

exitAction = new QAction(tr("Exit"), this);
Expand Down
1 change: 1 addition & 0 deletions gui/nmainmenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class NMainMenuBar : public QMenuBar
QAction *databaseStatusDialogAction;
QAction *restoreDatabaseAction;
QAction *accountDialogAction;
QAction *userMaintenanceAction;
QAction *aboutAction;

QAction *undoAction;
Expand Down
Loading

0 comments on commit 4c500a5

Please sign in to comment.