-
-
Save Michal-Szczepaniak/244f7d386434a755133397c12fd1118e to your computer and use it in GitHub Desktop.
error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef ACCOUNTSMODEL_H | |
#define ACCOUNTSMODEL_H | |
#include <QAbstractListModel> | |
#include "accountsoptionsmodel.h" | |
#include <libpurple/purple.h> | |
#include "defines.h" | |
class AccountsModel : public QAbstractListModel | |
{ | |
Q_OBJECT | |
public: | |
AccountsModel(); | |
enum AccountsRoles { | |
EnabledRole = Qt::UserRole + 1, | |
UsernameRole, | |
ProtocolRole, | |
OptionsRole | |
}; | |
void addAccount(const AccountsOptionsModel &account); | |
int rowCount(const QModelIndex & parent = QModelIndex()) const; | |
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; | |
protected: | |
QHash<int, QByteArray> roleNames() const; | |
private: | |
QList<AccountsOptionsModel> m_options; | |
}; | |
#endif // ACCOUNTSMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "accountsoptionsmodel.h" | |
#include "defines.h" | |
AccountsOptionsModel::AccountsOptionsModel(PurpleAccount* account) | |
{ | |
this->account = account; | |
username = QString::fromStdString(std::string(purple_account_get_username(account))); | |
protocol = QString::fromStdString(std::string(purple_account_get_protocol_id(account))); | |
enabled = purple_account_get_enabled(account, UI_ID); | |
GList *iter; | |
int i; | |
iter = purple_plugins_get_loaded(); | |
for (i = 0; iter; iter = iter->next) { | |
PurplePlugin *plugin = (PurplePlugin*) iter->data; | |
const char* pluginid = purple_plugin_get_id(plugin); | |
const char* accountid = purple_account_get_protocol_id(account); | |
if(strcmp(pluginid, accountid) != 0) continue; | |
PurplePluginInfo *info = plugin->info; | |
PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); | |
GList *l; | |
for (l = prpl_info->protocol_options; l != NULL; l = l->next) | |
{ | |
if(!l) continue; | |
PurpleAccountOption *purpleOption = (PurpleAccountOption *)l->data; | |
PurplePrefType type = purple_account_option_get_type(purpleOption); | |
const char* setting = purple_account_option_get_setting(purpleOption); | |
setting = purple_account_option_get_text(purpleOption); | |
if(PURPLE_PREF_STRING == type) { | |
Option option; | |
option.name = purple_account_option_get_text(purpleOption); | |
addOption(option); | |
} | |
} | |
} | |
} | |
void AccountsOptionsModel::addOption(const Option &option) | |
{ | |
beginInsertRows(QModelIndex(), rowCount(), rowCount()); | |
m_options << option; | |
endInsertRows(); | |
} | |
int AccountsOptionsModel::rowCount(const QModelIndex & parent) const { | |
Q_UNUSED(parent); | |
return m_options.count(); | |
} | |
QVariant AccountsOptionsModel::data(const QModelIndex & index, int role) const { | |
if (index.row() < 0 || index.row() >= m_options.count()) | |
return QVariant(); | |
const Option &option = m_options[index.row()]; | |
if (role == Name) | |
return option.name; | |
else if (role == Value) | |
return option.value; | |
else if (role == DefaultValue) | |
return option.defaultValue; | |
else if (role == Type) | |
return option.type; | |
return QVariant(); | |
} | |
bool AccountsOptionsModel::setData(const QModelIndex &index, const QVariant &value, int role) | |
{ | |
if (index.isValid()) { | |
Option &option = m_options[index.row()]; | |
if (role == Name) | |
option.name = value.toString(); | |
else if (role == Value) | |
option.value = value.toString(); | |
else if (role == DefaultValue) | |
option.defaultValue = value.toString(); | |
else if (role == Type) | |
option.type = value.toString(); | |
return true; | |
} | |
return false; | |
} | |
QHash<int, QByteArray> AccountsOptionsModel::roleNames() const { | |
QHash<int, QByteArray> roles; | |
roles[Name] = "name"; | |
roles[Value] = "value"; | |
roles[DefaultValue] = "defaultValue"; | |
roles[Type] = "type"; | |
return roles; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef ACCOUNTSOPTIONSMODEL_H | |
#define ACCOUNTSOPTIONSMODEL_H | |
#include <QAbstractListModel> | |
#include <libpurple/purple.h> | |
class AccountsOptionsModel : public QAbstractListModel | |
{ | |
// Q_OBJEsCT | |
public: | |
AccountsOptionsModel(PurpleAccount* account); | |
enum OptionRoles { | |
Name = Qt::UserRole + 1, | |
Value, | |
DefaultValue, | |
Type | |
}; | |
struct Option { | |
QString name; | |
QString value; | |
QString defaultValue; | |
QString type; | |
}; | |
QString username; | |
QString protocol; | |
bool enabled; | |
void addOption(const Option &option); | |
int rowCount(const QModelIndex & parent = QModelIndex()) const; | |
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; | |
bool setData(const QModelIndex &item, const QVariant &value, int role); | |
protected: | |
QHash<int, QByteArray> roleNames() const; | |
private: | |
QList<Option> m_options; | |
PurpleAccount* account; | |
}; | |
#endif // ACCOUNTSOPTIONSMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "accountsmodel.h" | |
AccountsModel::AccountsModel() | |
{ | |
int i; | |
GList* accounts = purple_accounts_get_all(); | |
for (accounts; accounts != NULL; accounts = accounts->next) { | |
AccountsOptionsModel option((PurpleAccount*)accounts->data); | |
addAccount(option); | |
} | |
} | |
void AccountsModel::addAccount(const AccountsOptionsModel &account) | |
{ | |
beginInsertRows(QModelIndex(), rowCount(), rowCount()); | |
m_options << account; | |
endInsertRows(); | |
} | |
int AccountsModel::rowCount(const QModelIndex & parent) const { | |
Q_UNUSED(parent); | |
return m_options.count(); | |
} | |
QVariant AccountsModel::data(const QModelIndex & index, int role) const { | |
if (index.row() < 0 || index.row() >= m_options.count()) | |
return QVariant(); | |
const AccountsOptionsModel &account = m_options[index.row()]; | |
if (role == EnabledRole) | |
return account.enabled; | |
else if (role == UsernameRole) | |
return account.username; | |
else if (role == ProtocolRole) | |
return account.protocol; | |
// else if (role == OptionsRole) | |
// return account; | |
return QVariant(); | |
} | |
QHash<int, QByteArray> AccountsModel::roleNames() const { | |
QHash<int, QByteArray> roles; | |
roles[EnabledRole] = "enabled"; | |
roles[UsernameRole] = "username"; | |
roles[ProtocolRole] = "protocol"; | |
roles[OptionsRole] = "options"; | |
return roles; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/usr/include/qt5/QtCore/qlist.h:431: error: use of deleted function ‘AccountsOptionsModel::AccountsOptionsModel(const AccountsOptionsModel&)’ | |
if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) n->v = new T(t); | |
^~~~~~~~ | |
/home/foidbgen/Qt Workspace/FishbookMesseenger/accountsoptionsmodel.h:7: error: ‘QAbstractListModel::QAbstractListModel(const QAbstractListModel&)’ is private within this context | |
/home/foidbgen/Qt Workspace/FishbookMesseenger/accountsoptionsmodel.h:7: error: use of deleted function ‘QAbstractListModel::QAbstractListModel(const QAbstractListModel&)’ | |
class AccountsOptionsModel : public QAbstractListModel | |
^~~~~~~~~~~~~~~~~~~~ | |
/usr/include/qt5/QtCore/qlist.h:432: error: use of deleted function ‘AccountsOptionsModel::AccountsOptionsModel(const AccountsOptionsModel&)’ | |
else if (QTypeInfo<T>::isComplex) new (n) T(t); | |
^~~~~~~~~~~~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment