Skip to content

Commit

Permalink
Merge pull request #6 from Emotyco/develop
Browse files Browse the repository at this point in the history
Version 0.3
  • Loading branch information
kdebiec authored Jan 7, 2018
2 parents d167459 + 7366061 commit 248ad9d
Show file tree
Hide file tree
Showing 2,739 changed files with 29,097 additions and 3,889 deletions.
2 changes: 1 addition & 1 deletion Bridge/LoginWindow/loginwindow_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include "Util/runstatehelper.h"
#endif

int loginwindow_main(int argc, char **argv)
int loginwindow_main()
{
QEventLoop app;

Expand Down
2 changes: 1 addition & 1 deletion Bridge/LoginWindow/loginwindow_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
#define LOGINWINDOW_MAIN_H


int loginwindow_main(int argc, char **argv);
int loginwindow_main();

#endif
6 changes: 6 additions & 0 deletions Bridge/MainWindow/mainwindowpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ MainWindowPanel::MainWindowPanel(HWND hWnd) : QWinView(hWnd)
ctxt->setContextProperty("base64", base64);

ctxt->setContextProperty("gxsModel", ContactsModel::getInstance());
gxs_avatars = new GXSAvatars();
ctxt->setContextProperty("gxs_avatars", gxs_avatars);

contactsModel = new ContactsSortModel();
contactsModel->setSourceModel(ContactsModel::getInstance());
Expand All @@ -98,6 +100,10 @@ MainWindowPanel::~MainWindowPanel()
if(identitiesModel != NULL)
delete identitiesModel;
identitiesModel = NULL;

if(gxs_avatars != NULL)
delete gxs_avatars;
gxs_avatars = NULL;
}

// Button events
Expand Down
3 changes: 2 additions & 1 deletion Bridge/MainWindow/mainwindowpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "Bridge/Windows/qwinview.h"
#include "libresapilocalclient.h"
#include "Util/base64.h"

#include "Util/gxsavatars.h"
#include "Bridge/Models/contactssortmodel.h"
#include "Bridge/Models/identitiessortmodel.h"

Expand Down Expand Up @@ -57,6 +57,7 @@ public slots:
HWND windowHandle;
LibresapiLocalClient *rsApi;
Base64 *base64;
GXSAvatars *gxs_avatars;

ContactsSortModel *contactsModel;
IdentitiesSortModel *identitiesModel;
Expand Down
147 changes: 147 additions & 0 deletions Bridge/Models/cardsmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/****************************************************************
* This file is part of Emoty.
* Emoty is distributed under the following license:
*
* Copyright (C) 2017, Konrad Dębiec
*
* Emoty is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* Emoty is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "cardsmodel.h"

int CardsModel::storeCard(QJSValue cardObject, QString name, bool isIcon, QString source, int indicatorNumber)
{
beginInsertRows(QModelIndex(), cardsList.size(), cardsList.size());
counter++;
cardsList.push_back(Card(cardObject, name, isIcon, source, counter, 0));
endInsertRows();

return counter;
}

bool CardsModel::removeCard(int index)
{
std::list<Card>::iterator vit = cardsList.begin();
for(int i = 0; vit != cardsList.end(); ++vit)
{
if ( index == (*vit).index)
{
beginRemoveRows(QModelIndex(), i, i);
cardsList.erase(vit);
endRemoveRows();
return true;
}

++i;
}

return false;
}

QJSValue CardsModel::getCard(int index)
{
std::list<Card>::iterator vit = cardsList.begin();
for(int i = 0; vit != cardsList.end(); ++vit)
{
if ( index == (*vit).index)
{
return (*vit).cardObject;
}

++i;
}
}

QJSValue CardsModel::getCardByListIndex(int index)
{
std::list<Card>::iterator vit = cardsList.begin();
for(int i = 0; vit != cardsList.end(); ++vit)
{
if ( index == i)
{
return (*vit).cardObject;
}

++i;
}
}

bool CardsModel::setIndicatorNumber(int cardIndex, int indicatorNumber)
{
std::list<Card>::iterator vit = cardsList.begin();
for(int i = 0; vit != cardsList.end(); ++vit)
{
if ( cardIndex == (*vit).index)
{
(*vit).indicator = indicatorNumber;
emit dataChanged(index(i),index(i));

return true;
}

++i;
}

return false;
}

int CardsModel::rowCount(const QModelIndex &) const
{
return cardsList.size();
}

QVariant CardsModel::data(const QModelIndex & index, int role) const
{
int idx = index.row();

if(idx < 0 || idx >= cardsList.size())
return QVariant("Something went wrong...");

std::list<Card>::const_iterator vit = cardsList.begin();
for(int i = 0; vit != cardsList.end(); ++vit)
{
if(idx == i)
break;

++i;
}

if(role == NameRole)
return (*vit).name;
else if(role == IsIconRole)
return (*vit).isIcon;
else if(role == SourceRole)
return (*vit).source;
else if(role == IndexRole)
return (*vit).index;
else if(role == IndicatorRole)
return (*vit).indicator;

return QVariant();
}

QHash<int, QByteArray> CardsModel::roleNames() const
{
QHash<int, QByteArray> roles;

roles[CardObjectRole] = "cardObject";
roles[NameRole] = "name";
roles[IsIconRole] = "isIcon";
roles[SourceRole] = "source";
roles[IndexRole] = "cardIndex";
roles[IndicatorRole] = "indicator";

return roles;
}
86 changes: 86 additions & 0 deletions Bridge/Models/cardsmodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/****************************************************************
* This file is part of Emoty.
* Emoty is distributed under the following license:
*
* Copyright (C) 2017, Konrad Dębiec
*
* Emoty is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* Emoty is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef CARDSMODEL_H
#define CARDSMODEL_H

//Qt
#include <QAbstractListModel>
#include <QQmlEngine>
#include <QJSValue>
#include <QMap>

class CardsModel : public QAbstractListModel
{
Q_OBJECT
public:
enum IvitationRoles{
CardObjectRole,
NameRole,
IsIconRole,
SourceRole,
IndexRole,
IndicatorRole
};

CardsModel(QObject *parent = 0)
: QAbstractListModel(parent), counter(0)
{}

virtual int rowCount(const QModelIndex & parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;

public slots:
int storeCard(QJSValue cardObject, QString name, bool isIcon, QString source, int indicatorNumber);
bool removeCard(int index);
QJSValue getCard(int index);
QJSValue getCardByListIndex(int index);
bool setIndicatorNumber(int index, int indicatorNumber);

protected:
virtual QHash<int, QByteArray> roleNames() const;

private:
struct Card {
Card(QJSValue cardObject, QString name,
bool isIcon, QString source, int index, int indicator)
: cardObject(cardObject), name(name),
isIcon(isIcon), source(source),
index(index), indicator(indicator)
{}

QJSValue cardObject;
QString name;
bool isIcon;
QString source;
int index;
int indicator;
};

int counter;
std::list<Card> cardsList;
};

static void registerCardsModelTypes() {
qmlRegisterType<CardsModel>("CardsModel", 0, 2, "CardsModel");
}

#endif // CARDSMODEL_H
36 changes: 24 additions & 12 deletions Bridge/Models/contactsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void ContactsModel::loadJSONContacts(QString json)
jsonContact.value("gxs_id").toString(),
jsonContact.value("pgp_id").toString(),
"undefined",
"0",
0,
"",
jsonContact.value("is_contact").toBool(),
jsonContact.value("pgp_linked").toBool(),
Expand Down Expand Up @@ -139,7 +139,7 @@ void ContactsModel::loadJSONContacts(QString json)
jsonContact.value("gxs_id").toString(),
jsonContact.value("pgp_id").toString(),
"undefined",
"0",
0,
"",
jsonContact.value("is_contact").toBool(),
jsonContact.value("pgp_linked").toBool(),
Expand Down Expand Up @@ -261,7 +261,7 @@ void ContactsModel::loadJSONStatus(QString json)
"",
jsonPGP.value("pgp_id").toString(),
"undefined",
"0",
0,
"",
true,
true,
Expand Down Expand Up @@ -303,11 +303,6 @@ void ContactsModel::loadJSONUnread(QString json)
{
QJsonObject qJsonObject = QJsonDocument::fromJson(json.toUtf8()).object();

if(unreadStateToken == qJsonObject.value("statetoken").toInt())
return;

unreadStateToken = qJsonObject.value("statetoken").toInt();

QJsonValue jsData = qJsonObject.value("data");
if(!jsData.isNull() && jsData.isArray())
{
Expand All @@ -317,20 +312,32 @@ void ContactsModel::loadJSONUnread(QString json)
for(std::list<Contact>::iterator vit = contactsData.begin(); vit != contactsData.end(); ++vit)
{
bool clear = true;
bool firstChat = true;
for(QJsonArray::iterator it = jsDataArray.begin(); it != jsDataArray.end(); it++)
{
QJsonObject jsonStatus = (*it).toObject();

if(jsonStatus.value("is_distant_chat_id").toBool()
&& (*vit).gxs_id == jsonStatus.value("remote_author_id").toString())
{
(*vit).unread_count = jsonStatus.value("unread_count").toString();
if(firstChat) {
(*vit).unread_count = jsonStatus.value("unread_count").toString().toInt();
(*vit).chatList.clear();
}
else
(*vit).unread_count += jsonStatus.value("unread_count").toString().toInt();

(*vit).chatList.append(jsonStatus.value("chat_id").toString());

firstChat = false;
clear = false;
}
}

if(clear)
(*vit).unread_count = "0";
if(clear) {
(*vit).unread_count = 0;
(*vit).chatList.clear();
}

emit dataChanged(index(i),index(i));
i++;
Expand Down Expand Up @@ -360,7 +367,7 @@ void ContactsModel::loadJSONAvatar(QString gxs_id, QString json)
}
}

int ContactsModel::rowCount(const QModelIndex & parent) const
int ContactsModel::rowCount(const QModelIndex &) const
{
return contactsData.size();
}
Expand Down Expand Up @@ -399,6 +406,10 @@ QVariant ContactsModel::data(const QModelIndex & index, int role) const
return (*vit).avatar;
else if(role == IsOnlyOneRole)
return (*vit).is_only;
else if(role == ChatListRole)
return (*vit).chatList;

return QVariant();
}

QHash<int, QByteArray> ContactsModel::roleNames() const
Expand All @@ -414,6 +425,7 @@ QHash<int, QByteArray> ContactsModel::roleNames() const
roles[PgpLinkedRole] = "pgp_linked";
roles[AvatarRole] = "avatar";
roles[IsOnlyOneRole] = "is_only";
roles[ChatListRole] = "chat_list";

return roles;
}
Loading

0 comments on commit 248ad9d

Please sign in to comment.