Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Everybody loves code cleanups! CLEANUPS CLEANUPS CLEANUPS CLEANUPS.

And headers. Headers are so awesome. OMG.

Replaced MySettings.cpp and SettingsDBWrapper with one class which does
exactly the same but in more... logical way. Removed stuff from
MessageWrapper which shouldn't be there, I think I could remove it as
soon as I find a way to do exactly the same in JavaScript. Merged
AccountsListModel.h and AccountsListModel.cpp cause who needs cpp file
if you can do all this in header?
  • Loading branch information
ksiazkowicz committed Dec 14, 2013
1 parent 6b63a67 commit b61abed
Show file tree
Hide file tree
Showing 23 changed files with 592 additions and 982 deletions.
11 changes: 4 additions & 7 deletions Lightbulb.pro
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,20 @@ SOURCES += src/main.cpp \
src/ListModel.cpp \
src/cache/MyCache.cpp \
src/cache/StoreVCard.cpp \
src/database/MySettings.cpp \
src/xmpp/MessageWrapper.cpp \
src/AccountsItemModel.cpp \
src/AccountsListModel.cpp \
src/cache/QMLVCard.cpp \
src/avkon/LightbulbHSWidget.cpp \
src/database/DatabaseManager.cpp \
src/avkon/QAvkonHelper.cpp \
src/database/SettingsDBWrapper.cpp \
src/xmpp/XmppConnectivity.cpp \
src/database/DatabaseWorker.cpp
src/database/DatabaseWorker.cpp \
src/database/Settings.cpp

HEADERS += src/xmpp/MyXmppClient.h \
src/ListModel.h \
src/cache/MyCache.h \
src/cache/StoreVCard.h \
src/database/MySettings.h \
src/xmpp/MessageWrapper.h \
src/AccountsItemModel.h \
src/AccountsListModel.h \
Expand All @@ -106,10 +103,10 @@ HEADERS += src/xmpp/MyXmppClient.h \
src/avkon/LightbulbHSWidget.h \
src/database/DatabaseManager.h \
src/avkon/QAvkonHelper.h \
src/database/SettingsDBWrapper.h \
src/avkon/SymbiosisAPIClient.h \
src/xmpp/XmppConnectivity.h \
src/database/DatabaseWorker.h
src/database/DatabaseWorker.h \
src/database/Settings.h

OTHER_FILES += README.md \
qml/Dialogs/AddContact.qml \
Expand Down
5 changes: 2 additions & 3 deletions qml/Dialogs/Chats.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ CommonDialog {
} //imgPresence
Text {
id: txtJid
property string contact: xmppClient.getPropertyByJid(jid,"name")
property int unreadMsg: parseInt(xmppClient.getPropertyByJid(jid,"unreadMsg"))
anchors { left: imgPresence.right; right: imgPresenceR.left; leftMargin: 10; rightMargin: 10; verticalCenter: parent.verticalCenter }
width: parent.width
maximumLineCount: (rosterItemHeight/22) > 1 ? (rosterItemHeight/22) : 1
text: (contact === "" ? jid : contact) + (unreadMsg > 0 ? " [" + unreadMsg + "]" : "")
text: (name === "" ? jid : name) + (unreadMsg > 0 ? " [" + unreadMsg + "]" : "")
onLinkActivated: { main.url=link; linkContextMenu.open()}
wrapMode: Text.Wrap
font.pixelSize: 16
Expand All @@ -75,7 +74,7 @@ CommonDialog {
onClicked: {
listViewChats.currentIndex = index
xmppClient.chatJid = jid
xmppClient.contactName = txtJid.contact
xmppClient.contactName = name
main.globalUnreadCount = main.globalUnreadCount - txtJid.unreadMsg
xmppClient.resetUnreadMessages( jid )
if (settings.gBool("behavior","enableHsWidget")) {
Expand Down
21 changes: 8 additions & 13 deletions qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ PageStackWindow {
initAccount()
checkIfFirstRun()
xmppClient.keepAlive = settings.gInt("behavior", "keepAliveInterval")
xmppClient.archiveIncMessage = settings.gBool("behavior", "archiveIncMessage")
if (settings.gBool("behavior","goOnlineOnStart")) { xmppClient.setMyPresence( XmppClient.Online, lastStatus ) }
}

Expand Down Expand Up @@ -185,23 +184,19 @@ PageStackWindow {
_existDefaultAccount = false
for( var j=0; j<settings.accounts.count(); j++ )
{
if( settings.accIsDefault( j ) )
if( settings.gBool( settings.getJidByIndex( j ),"is_default" ) )
{
_existDefaultAccount = true
xmppClient.myBareJid = settings.accGetJid( j );
xmppClient.myPassword = settings.accGetPassword( j );
xmppClient.resource = settings.accGetResource( j );
xmppClient.myBareJid = settings.getJidByIndex( j );
xmppClient.myPassword = settings.gStr( settings.getJidByIndex( j ),"passwd" );
xmppClient.resource = settings.gStr( settings.getJidByIndex( j ), "resource" )

if( settings.accIsManuallyHostPort( j ) ) {
xmppClient.host = settings.accGetHost( j );
if( settings.gBool( settings.getJidByIndex( j ),"use_host_port" ) ) {
xmppClient.host = settings.gStr(settings.getJidByIndex(j), "host")
xmppClient.port = settings.gInt(settings.getJidByIndex(j), "port")
} else {
xmppClient.host = "";
}

if( settings.accIsManuallyHostPort( j ) ) {
xmppClient.port = settings.accGetPort( j );
} else {
xmppClient.port = 0;
xmppClient.port = 5222;
}

xmppClient.accountId = j;
Expand Down
58 changes: 24 additions & 34 deletions src/accountsitemmodel.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
/********************************************************************
src/AccountsItemModel.cpp
-- implements item model for account
Copyright (c) 2012 Anatoliy Kozlov
This file is part of Lightbulb and was derived from MeegIM.
Lightbulb 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.
This program 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, see <http://www.gnu.org/licenses/>.
*********************************************************************/

#include "accountsitemmodel.h"


AccountsItemModel::AccountsItemModel( const QString &_accountJid,
const QString &_accountPasswd,
const QString &_accountIcon,
const QString &_accountType,
const QString &_accountResource,
const QString &_accountHost,
const int _accountPort,
Expand All @@ -14,8 +36,6 @@ AccountsItemModel::AccountsItemModel( const QString &_accountJid,
ListItem(parent),
m_jid(_accountJid),
m_passwd(_accountPasswd),
m_icon(_accountIcon),
m_type(_accountType),
m_resource(_accountResource),
m_host(_accountHost),
m_port(_accountPort),
Expand All @@ -40,14 +60,6 @@ void AccountsItemModel::setPasswd(QString &_accountPasswd)
}
}

void AccountsItemModel::setIcon(QString &_accountIcon)
{
if(m_icon != _accountIcon) {
m_icon = _accountIcon;
emit dataChanged();
}
}

void AccountsItemModel::setDefault(bool &_accountDefault)
{
if(m_default != _accountDefault) {
Expand All @@ -56,22 +68,6 @@ void AccountsItemModel::setDefault(bool &_accountDefault)
}
}

void AccountsItemModel::setType(QString &_accountType)
{
if(m_type!= _accountType) {
m_type = _accountType;
emit dataChanged();
}
}

void AccountsItemModel::setResource(QString &_accountResource)
{
if(m_type!= _accountResource) {
m_type = _accountResource;
emit dataChanged();
}
}

void AccountsItemModel::setHost(QString &_accountHost)
{
if(m_host!= _accountHost) {
Expand Down Expand Up @@ -104,9 +100,7 @@ QHash<int, QByteArray> AccountsItemModel::roleNames() const
QHash<int, QByteArray> names;
names[accJid] = "accJid";
names[accPasswd] = "accPasswd";
names[accIcon] = "accIcon";
names[accDefault] = "accDefault";
names[accType] = "accType";
names[accResource] = "accResource";
names[accHost] = "accHost";
names[accPort] = "accPort";
Expand All @@ -121,12 +115,8 @@ QVariant AccountsItemModel::data(int role) const
return jid();
case accPasswd:
return passwd();
case accIcon:
return icon();
case accDefault:
return isDefault();
case accType:
return type();
case accResource:
return resource();
case accHost:
Expand Down
36 changes: 25 additions & 11 deletions src/accountsitemmodel.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/********************************************************************
src/AccountsItemModel.h
-- implements item model for account
Copyright (c) 2012 Anatoliy Kozlov
This file is part of Lightbulb and was derived from MeegIM.
Lightbulb 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.
This program 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, see <http://www.gnu.org/licenses/>.
*********************************************************************/

#ifndef ACCOUNTSITEMMODEL_H
#define ACCOUNTSITEMMODEL_H

Expand All @@ -11,9 +35,7 @@ class AccountsItemModel : public ListItem
enum Roles {
accJid = Qt::UserRole+1,
accPasswd,
accIcon,
accDefault,
accType,
accResource,
accHost,
accPort,
Expand All @@ -24,8 +46,6 @@ class AccountsItemModel : public ListItem
AccountsItemModel(QObject *parent = 0): ListItem(parent) {}
explicit AccountsItemModel( const QString &_accountJid,
const QString &_accountPasswd,
const QString &_accountIcon,
const QString &_accountType,
const QString &_accountResource,
const QString &_accountHost,
const int _accountPort,
Expand All @@ -40,19 +60,15 @@ class AccountsItemModel : public ListItem

void setJid( QString &_accountJid );
void setPasswd( QString &_accountPasswd );
void setIcon( QString &_accountIcon );

void setDefault( bool &_accountDefault );
void setType( QString &_accountType );
void setResource( QString &_accountResource );
void setHost( QString &_accountHost );
void setPort( int _accountPort );
void setManuallyHostPort( bool _manuallyHostPort );

inline QString jid() const { return m_jid; }
inline QString passwd() const { return m_passwd; }
inline QString icon() const { return m_icon; }
inline bool isDefault() const { return m_default; }
inline QString type() const { return m_type; }
inline QString resource() const { return m_resource; }
inline QString host() const { return m_host; }
inline int port() const { return m_port; }
Expand All @@ -62,8 +78,6 @@ class AccountsItemModel : public ListItem
private:
QString m_jid;
QString m_passwd;
QString m_icon;
QString m_type;
QString m_resource;
QString m_host;
int m_port;
Expand Down
23 changes: 0 additions & 23 deletions src/accountslistmodel.cpp

This file was deleted.

41 changes: 34 additions & 7 deletions src/accountslistmodel.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
/********************************************************************
src/AccountsListModel.h
-- implements list model for accounts
Copyright (c) 2012 Anatoliy Kozlov,
Maciej Janiszewski
This file is part of Lightbulb and was derived from MeegIM.
Lightbulb 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.
This program 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, see <http://www.gnu.org/licenses/>.
*********************************************************************/

#ifndef ACCOUNTSLISTMODEL_H
#define ACCOUNTSLISTMODEL_H

#include "listmodel.h"
#include "accountsitemmodel.h"
#include "ListModel.h"
#include "AccountsItemModel.h"

class AccountsListModel : public ListModel
{
Q_OBJECT
public:
explicit AccountsListModel( QObject *parent = 0 );
AccountsListModel( QObject *parent ) :ListModel( new AccountsItemModel, parent )
{
}

Q_INVOKABLE void append( AccountsItemModel *item );
Q_INVOKABLE void remove( int index );
Q_INVOKABLE int count();
Q_INVOKABLE void clearList();
Q_INVOKABLE void append( AccountsItemModel *item ) { this->appendRow(item); }
Q_INVOKABLE void remove( int index ) { this->removeRow( index ); }
Q_INVOKABLE int count() { return this->rowCount(); }
Q_INVOKABLE void clearList() { this->clear(); }
};

#endif // ACCOUNTSLISTMODEL_H
Loading

0 comments on commit b61abed

Please sign in to comment.