Skip to content

Commit

Permalink
Merge branch 'deXol-developBLEImplementMMMCommands'
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulh committed Oct 22, 2019
2 parents 532184a + 707a21c commit d81c3af
Show file tree
Hide file tree
Showing 32 changed files with 551 additions and 46 deletions.
6 changes: 4 additions & 2 deletions gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ SOURCES += src/main_gui.cpp \
src/Settings/DeviceSettingsMini.cpp \
src/Settings/SettingsGuiHelper.cpp \
src/Settings/SettingsGuiMini.cpp \
src/Settings/SettingsGuiBLE.cpp
src/Settings/SettingsGuiBLE.cpp \
src/DeviceDetector.cpp

HEADERS += src/MainWindow.h \
src/ParseDomain.h \
Expand Down Expand Up @@ -119,7 +120,8 @@ HEADERS += src/MainWindow.h \
src/Settings/SettingsGuiHelper.h \
src/Settings/SettingsGuiMini.h \
src/Settings/SettingsGuiBLE.h \
src/Settings/ISettingsGui.h
src/Settings/ISettingsGui.h \
src/DeviceDetector.h

mac {
HEADERS += src/MacUtils.h \
Expand Down
2 changes: 2 additions & 0 deletions src/AppGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "DbMasterController.h"
#include "PromptWidget.h"
#include "SystemNotifications/SystemNotification.h"
#include "DeviceDetector.h"

#ifdef Q_OS_WIN
#include "SystemNotifications/SystemNotificationWindows.h"
Expand Down Expand Up @@ -86,6 +87,7 @@ bool AppGui::initialize()
#ifdef Q_OS_WIN
SystemNotification::instance();
#endif
DeviceDetector::instance();

setQuitOnLastWindowClosed(false);

Expand Down
8 changes: 8 additions & 0 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ QHash<Common::MPStatus, QString> Common::MPStatusString = {
{ Common::UnkownSmartcad, "UnkownSmartcad" }
};

QMap<int, QString> Common::BLE_CATEGORY_COLOR = {
{0, "black"},
{1, "red"},
{2, "blue"},
{3, "green"},
{4, "orange"}
};

Common::MPStatus Common::statusFromString(const QString &st)
{
for (auto it = MPStatusString.begin();it != MPStatusString.end();it++)
Expand Down
13 changes: 13 additions & 0 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#define MP_NODE_SIZE 132
#define MP_NODE_DATA_ENC_SIZE 128

#define MAX_BLE_CAT_NUM 10

#define MOOLTIPASS_BLOCK_SIZE 32
#define MOOLTIPASS_DESC_SIZE 23 //max size allowed for description

Expand Down Expand Up @@ -119,6 +121,12 @@ template<class T>
T const& qAsConst(T&t){return t;}
#endif

//Q_DISABLE_COPY_MOVE from Qt 5.15
#define DISABLE_COPY_MOVE(Class) \
Q_DISABLE_COPY(Class) \
Class(const Class &&) Q_DECL_EQ_DELETE;\
Class &operator=(const Class &&) Q_DECL_EQ_DELETE;

class Common
{
public:
Expand All @@ -144,6 +152,7 @@ class Common
UnkownSmartcad = 9,
} MPStatus;
static QHash<MPStatus, QString> MPStatusUserString, MPStatusString;
static QMap<int, QString> BLE_CATEGORY_COLOR;

static Common::MPStatus statusFromString(const QString &st);

Expand Down Expand Up @@ -278,6 +287,10 @@ Q_DECLARE_METATYPE(Common::MPHwVersion)
"border: 1px solid #FcFcFc;"\
"}"

#define CSS_CREDVIEW_SELECTION "QTreeView::item:selected {" \
"background-color: rgba( 128, 128, 128, 100);" \
"}"

enum class CloseBehavior
{
CloseApp,
Expand Down
41 changes: 40 additions & 1 deletion src/CredentialModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "LoginItem.h"
#include "TreeItem.h"
#include "ParseDomain.h"
#include "DeviceDetector.h"

CredentialModel::CredentialModel(QObject *parent) : QAbstractItemModel(parent)
{
Expand Down Expand Up @@ -216,6 +217,12 @@ void CredentialModel::load(const QJsonArray &json)
QDate dUpdatedDate = QDate::fromString(cnode["date_last_used"].toString(), Qt::ISODate);
pLoginItem->setAccessedDate(dUpdatedDate);

// Update login item category
if (DeviceDetector::instance().isBle())
{
pLoginItem->setCategory(cnode["category"].toVariant().toInt());
}

QJsonArray a = cnode["address"].toArray();
if (a.size() < 2)
{
Expand Down Expand Up @@ -274,7 +281,20 @@ ServiceItem *CredentialModel::getServiceItemByIndex(const QModelIndex &idx) cons
return dynamic_cast<ServiceItem *>(getItemByIndex(idx));
}

void CredentialModel::updateLoginItem(const QModelIndex &idx, const QString &sPassword, const QString &sDescription, const QString &sName)
QString CredentialModel::getCategoryName(int catId) const
{
return m_categories[catId];
}

void CredentialModel::updateCategories(const QString &cat1, const QString &cat2, const QString &cat3, const QString &cat4)
{
m_categories[1] = cat1;
m_categories[2] = cat2;
m_categories[3] = cat3;
m_categories[4] = cat4;
}

void CredentialModel::updateLoginItem(const QModelIndex &idx, const QString &sPassword, const QString &sDescription, const QString &sName, int iCat)
{
// Retrieve item
LoginItem *pLoginItem = getLoginItemByIndex(idx);
Expand All @@ -283,6 +303,10 @@ void CredentialModel::updateLoginItem(const QModelIndex &idx, const QString &sPa
updateLoginItem(idx, PasswordRole, sPassword);
updateLoginItem(idx, DescriptionRole, sDescription);
updateLoginItem(idx, ItemNameRole, sName);
if (DeviceDetector::instance().isBle())
{
updateLoginItem(idx, CategoryRole, iCat);
}
}
}

Expand Down Expand Up @@ -354,6 +378,21 @@ void CredentialModel::updateLoginItem(const QModelIndex &idx, const ItemRole &ro
}
break;
}
case CategoryRole:
{
int iCat = vValue.toInt();
if (iCat != pLoginItem->category())
{
pLoginItem->setCategory(iCat);
// When category changed reset favorite
if (pLoginItem->favorite() > Common::FAV_NOT_SET)
{
pLoginItem->setFavorite(Common::FAV_NOT_SET);
}
bChanged = true;
}
break;
}
default: break;
}
if (bChanged)
Expand Down
8 changes: 6 additions & 2 deletions src/CredentialModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class CredentialModel : public QAbstractItemModel
DescriptionRole,
DateUpdatedRole,
DateAccessedRole,
FavoriteRole
FavoriteRole,
CategoryRole
};

CredentialModel(QObject *parent=nullptr);
Expand All @@ -45,18 +46,21 @@ class CredentialModel : public QAbstractItemModel
void addCredential(QString sServiceName, const QString &sLoginName, const QString &sPassword, const QString &sDescription="");
bool removeCredential(const QModelIndex &idx);
TreeItem *getItemByIndex(const QModelIndex &idx) const;
void updateLoginItem(const QModelIndex &idx, const QString &sPassword, const QString &sDescription, const QString &sName);
void updateLoginItem(const QModelIndex &idx, const QString &sPassword, const QString &sDescription, const QString &sName, int iCat);
void updateLoginItem(const QModelIndex &idx, const ItemRole &role, const QVariant &vValue);
void clear();
QModelIndex getServiceIndexByName(const QString &sServiceName, int column = 0) const;
LoginItem *getLoginItemByIndex(const QModelIndex &idx) const;
ServiceItem *getServiceItemByIndex(const QModelIndex &idx) const;
QString getCategoryName(int catId) const;
void updateCategories(const QString& cat1, const QString& cat2, const QString& cat3, const QString& cat4);

private:
ServiceItem *addService(const QString &sServiceName);

private:
RootItem *m_pRootItem;
QList<QString> m_categories{tr("Default category"), "", "", "", ""};

signals:
void modelLoaded(bool bClearLoginDescription);
Expand Down
6 changes: 6 additions & 0 deletions src/CredentialView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ CredentialView::CredentialView(QWidget *parent) : QTreeView(parent)
, tempCurrentLoginItem(nullptr)
, columnBreakRatio(0.75)
{
#ifndef Q_OS_WIN
/* On Linux and Mac selected credential is
* not visible without this in the treeview.
*/
setStyleSheet(CSS_CREDVIEW_SELECTION);
#endif
m_tSelectionTimer.setInterval(50);
m_tSelectionTimer.setSingleShot(true);
connect(&m_tSelectionTimer, &QTimer::timeout, this, &CredentialView::onSelectionTimerTimeOut);
Expand Down
Loading

0 comments on commit d81c3af

Please sign in to comment.