diff --git a/code/flist_messenger/api/apihelpers.cpp b/code/flist_messenger/api/apihelpers.cpp index efc6271..3274593 100644 --- a/code/flist_messenger/api/apihelpers.cpp +++ b/code/flist_messenger/api/apihelpers.cpp @@ -1,13 +1,21 @@ #include "flist_api.h" +#if QT_VERSION >= 0x050000 +#include +#else #include +#endif #include namespace FHttpApi { QNetworkReply *Endpoint::request(QUrl u, QHash params) { - QUrl encParams; +#if QT_VERSION >= 0x050000 + QUrlQuery encParams; +#else + QUrl encParams; +#endif QHashIterator i(params); while(i.hasNext()) { @@ -18,11 +26,11 @@ QNetworkReply *Endpoint::request(QUrl u, QHash params) QNetworkRequest request(u); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); #if QT_VERSION >= 0x050000 - QIODevice postData = encParams.query(QUrl::FullyEncoded).toUtf8(); + QByteArray postData = encParams.query(QUrl::FullyEncoded).toUtf8(); #else QByteArray postData = encParams.encodedQuery(); #endif - QNetworkReply *reply = qnam->post(request, postData); + QNetworkReply *reply = qnam->post(request, postData); return reply; } diff --git a/code/flist_messenger/flist_account.cpp b/code/flist_messenger/flist_account.cpp index cda1434..1328676 100644 --- a/code/flist_messenger/flist_account.cpp +++ b/code/flist_messenger/flist_account.cpp @@ -25,13 +25,17 @@ void FAccount::loginSslErrors( QList sslerrors ) void FAccount::onLoginError(QString error_id, QString error_message) { - debugMessage("account->loginHttps() error!"); - emit loginError(this, "Login Error", QString("%1 (%2)").arg(error_message).arg(error_id)); + debugMessage("account->loginHttps() error!"); + if (error_message.compare("Password mismatch.")) { + emit loginError(this, "Login Error", QString("%1 (%2)").arg(error_message).arg(error_id)); + } else { + emit loginError(this, "Login Error", QString("%1").arg(error_message)); + } } void FAccount::loginHandle() { - debugMessage("account->loginHandle()"); + debugMessage("account->loginHandle()"); loginReply->deleteLater(); ticket = loginReply->ticket->ticket; @@ -55,7 +59,7 @@ void FAccount::loginHandle() void FAccount::loginStart() { - debugMessage("account->loginStart()"); + debugMessage("account->loginStart()"); ticketvalid = false; loginReply = fapi->getTicket(username, password); @@ -66,7 +70,7 @@ void FAccount::loginStart() void FAccount::loginUserPass(QString user, QString pass) { - debugMessage("account->loginUserPass()"); + debugMessage("account->loginUserPass()"); username = user; password = pass; valid = true; @@ -75,8 +79,8 @@ void FAccount::loginUserPass(QString user, QString pass) FSession *FAccount::getSession(QString sessionid) { - //debugMessage("account->getSession()"); - int i; + //debugMessage("account->getSession()"); + int i; //Find existing session, if any. for(i = 0; i < charactersessions.length(); i++) { if(charactersessions[i]->sessionid == sessionid) { diff --git a/code/flist_messenger/flist_api.h b/code/flist_messenger/flist_api.h index de8a2ab..04cf679 100644 --- a/code/flist_messenger/flist_api.h +++ b/code/flist_messenger/flist_api.h @@ -71,16 +71,13 @@ namespace FHttpApi // virtual Request *remFriend(cpTicket t, crQString from, crQString to) = 0; // virtual Request *acceptFriendRequest(cpTicket t, int request_id) = 0; // virtual Request *cancelFriendRequest(cpTicket t, int request_id) = 0; - // virtual Request > *getCharacterList(cpTicket t) = 0; - // /* Acceptable data types: // * Data_Kinks, Data_Description, Data_CustomKinks, Data_Images, Data_Infotags // */ // virtual Request *getCharacterData(cpTicket t, crQString name, DataTypes d = Data_QuickProfile) = 0; // virtual Request *getCharacterMemo(cpTicket t, int idCharacter) = 0; // virtual Request *setCharacterMemo(cpTicket t, int idCharacter, crQString memo); - // virtual Request *getIgnoreList(cpTicket t) = 0; // virtual Request *addIgnore(cpTicket t, int idCharacter) = 0; // virtual Request *addIgnore(cpTicket t, crQString character) = 0; diff --git a/code/flist_messenger/flist_channel.cpp b/code/flist_messenger/flist_channel.cpp index ddfa8d0..392b582 100644 --- a/code/flist_messenger/flist_channel.cpp +++ b/code/flist_messenger/flist_channel.cpp @@ -6,11 +6,11 @@ FChannel::FChannel(QObject *parent, FSession *session, QString name, QString title) : QObject(parent), session(session), - name(name), - title(title), + _name(name), + _title(title), characterlist(), operatorlist(), - joined(true), + _joined(true), mode(CHANNEL_MODE_BOTH) { if(name.startsWith("ADH-")) { @@ -25,11 +25,11 @@ void FChannel::addCharacter(QString charactername, bool notify) { if(!characterlist.contains(lowername) || characterlist.value(lowername).isEmpty()) { characterlist[lowername] = charactername; } - session->account->ui->addChannelCharacter(session, name, charactername, notify); + session->account->ui->addChannelCharacter(session, this->name(), charactername, notify); } void FChannel::removeCharacter(QString charactername) { characterlist.remove(charactername.toLower()); - session->account->ui->removeChannelCharacter(session, name, charactername); + session->account->ui->removeChannelCharacter(session, this->name(), charactername); } void FChannel::addOperator(QString charactername) { @@ -37,24 +37,24 @@ void FChannel::addOperator(QString charactername) { if(!operatorlist.contains(lowername) || operatorlist.value(lowername).isEmpty()) { operatorlist[lowername] = charactername; } - session->account->ui->setChannelOperator(session, name, charactername, true); + session->account->ui->setChannelOperator(session, this->name(), charactername, true); } void FChannel::removeOperator(QString charactername) { operatorlist.remove(charactername.toLower()); - session->account->ui->setChannelOperator(session, name, charactername, false); + session->account->ui->setChannelOperator(session, this->name(), charactername, false); } void FChannel::join() { - joined = true; - session->account->ui->joinChannel(session, name); + _joined = true; + session->account->ui->joinChannel(session, this->name()); } void FChannel::leave() { - joined = false; + _joined = false; characterlist.clear(); operatorlist.clear(); - session->account->ui->leaveChannel(session, name); + session->account->ui->leaveChannel(session, this->name()); } diff --git a/code/flist_messenger/flist_channel.h b/code/flist_messenger/flist_channel.h index 978025b..95597a6 100644 --- a/code/flist_messenger/flist_channel.h +++ b/code/flist_messenger/flist_channel.h @@ -25,9 +25,7 @@ class FChannel : public QObject explicit FChannel(QObject *parent, FSession *session, QString name, QString title); bool isCharacterPresent(QString charactername) {return characterlist.contains(charactername.toLower());} - bool isCharacterOperator(QString charactername) {return operatorlist.contains(charactername.toLower());} - //todo: Figure out a better function name than 'isJoined'. - bool isJoined() {return joined;} + bool isCharacterOperator(QString charactername) {return operatorlist.contains(charactername.toLower());} void addCharacter(QString charactername, bool notify); void removeCharacter(QString charactername); @@ -38,27 +36,27 @@ class FChannel : public QObject void join(); void leave(); - QString getTitle() {return title;} - void setTitle(QString title) {this->title = title;} + bool joined() {return _joined;} + QString title() {return _title;} + QString name() {return _name;} + QString description() {return _description;} - QString getDescription() {return description;} - void setDescription(QString &newdescription) {description = newdescription;} + void setTitle(const QString &newTitle) {this->_title = newTitle;} + void setDescription(const QString &newdescription) {_description = newdescription;} signals: public slots: -public: - //todo: Make the following private. - FSession *session; - QString name; // characterlist; // operatorlist; // chancharlevels; @@ -188,7 +188,7 @@ void FChannelPanel::sortChars() } } - //std::cout << "Gnome sorted userlist~." << std::endl; + //std::cout << "Gnome sorted userlist~." << std::endl; } bool FChannelPanel::isOp ( FCharacter* character ) diff --git a/code/flist_messenger/flist_channelpanel.h b/code/flist_messenger/flist_channelpanel.h index 4bc4f27..1d32cea 100644 --- a/code/flist_messenger/flist_channelpanel.h +++ b/code/flist_messenger/flist_channelpanel.h @@ -126,6 +126,7 @@ class FChannelPanel void printChannel ( QTextBrowser* textEdit ); QPushButton* pushButton; static BBCodeParser* bbparser; + private: bool active; // Will be no when the user leaves. This way, logs are kept.~ QString recipientName; // For PM tabs. diff --git a/code/flist_messenger/flist_global.cpp b/code/flist_messenger/flist_global.cpp index 882c93a..b3f8a50 100644 --- a/code/flist_messenger/flist_global.cpp +++ b/code/flist_messenger/flist_global.cpp @@ -15,7 +15,7 @@ QString logpath; FSettings *settings = 0; FHttpApi::Endpoint *fapi = 0; -void debugMessage(QString str) { +void debugMessage(QString str, DebugMessageType::DBG_GENERAL) { std::cout << str.toUtf8().data() << std::endl; } diff --git a/code/flist_messenger/flist_global.h b/code/flist_messenger/flist_global.h index 77df17e..b16de74 100644 --- a/code/flist_messenger/flist_global.h +++ b/code/flist_messenger/flist_global.h @@ -3,6 +3,7 @@ #include #include "flist_api.h" +#include "flist_enums.h" class BBCodeParser; class FSettings; @@ -12,9 +13,9 @@ extern BBCodeParser *bbcodeparser; extern FHttpApi::Endpoint *fapi; extern FSettings *settings; -void debugMessage(QString str); -void debugMessage(std::string str); -void debugMessage(const char *str); +void debugMessage(QString str, DebugMessageType d); +void debugMessage(std::string str, DebugMessageType d); +void debugMessage(const char *str, DebugMessageType d); void globalInit(); void globalQuit(); bool is_broken_escaped_apos(std::string const &data, std::string::size_type n); @@ -31,6 +32,14 @@ void centerOnScreen(QWidget *widge); #define FLIST_VERSION FLIST_NAME " " FLIST_VERSIONNUM #define FLIST_CLIENTID "F-List Desktop Client" +enum dbgMessageTypes { + DBG_GENERAL 0, + DBG_SERVER 1 +}; + +#define DBG_GENERAL 0 +#define DBG_SERVER + #define FLIST_CHAT_SERVER "chat.f-list.net" //#define FLIST_CHAT_SERVER_PORT 8722 //Test server diff --git a/code/flist_messenger/flist_session.cpp b/code/flist_messenger/flist_session.cpp index 1e35843..cf49f23 100644 --- a/code/flist_messenger/flist_session.cpp +++ b/code/flist_messenger/flist_session.cpp @@ -100,7 +100,7 @@ FChannel *FSession::addChannel(QString name, QString title) if(channellist.contains(name)) { channel = channellist[name]; //Ensure that the channel's title is set correctly for ad-hoc channels. - if(name != title && channel->getTitle() != title) { + if(name != title && channel->title() != title) { channel->setTitle(title); } return channel; @@ -310,7 +310,7 @@ void FSession::wsSend(std::string &input) //textEdit->append ( "Attempted to send a message, but client is disconnected." ); } else { fix_broken_escaped_apos ( input ); - debugMessage( ">>" + input); + // debugMessage( ">>" + input); QByteArray buf; QDataStream stream ( &buf, QIODevice::WriteOnly ); input.resize ( input.length() ); @@ -356,7 +356,7 @@ void FSession::wsSend(std::string &input) void FSession::wsRecv(std::string packet) { - debugMessage("<<" + packet); + // debugMessage("<<" + packet); try { std::string cmd = packet.substr(0, 3); JSONNode nodes; @@ -672,7 +672,7 @@ COMMAND(RMO) return; } QString message = "[session=%1]%2[/session]'s mode has been changed to: %3"; - message = bbcodeparser->parse(message).arg(channel->getTitle()).arg(channelname).arg(modedescription); + message = bbcodeparser->parse(message).arg(channel->title()).arg(channelname).arg(modedescription); account->ui->setChannelMode(this, channelname, channel->mode); account->ui->messageChannel(this, channelname, message, MESSAGE_TYPE_CHANNEL_MODE, true); } @@ -784,7 +784,7 @@ COMMAND(CBUCKU) debugMessage(QString("[SERVER BUG] Was told about character '%1' being %4 from channel '%2' by '%3', but the channel '%2' is unknown (or never joined). %5").arg(charactername).arg(channelname).arg(operatorname).arg(kicktype).arg(QString::fromStdString(rawpacket))); return; } - if(!channel->isJoined()) { + if(!channel->joined()) { debugMessage(QString("[SERVER BUG] Was told about character '%1' being %4 from channel '%2' by '%3', but this session is no longer joined with channel '%2'. %5").arg(charactername).arg(channelname).arg(operatorname).arg(kicktype).arg(QString::fromStdString(rawpacket))); return; } @@ -795,7 +795,7 @@ COMMAND(CBUCKU) if(!channel->isCharacterOperator(operatorname) && !isCharacterOperator(operatorname)) { debugMessage(QString("[SERVER BUG] Was told about character '%1' being %4 from channel '%2' by '%3', but '%3' is not a channel operator or a server operator! %5").arg(charactername).arg(channelname).arg(operatorname).arg(kicktype).arg(QString::fromStdString(rawpacket))); } - QString message = QString("%1 has %4 %2 from %3.").arg(operatorname).arg(charactername).arg(channel->getTitle()).arg(kicktype); + QString message = QString("%1 has %4 %2 from %3.").arg(operatorname).arg(charactername).arg(channel->title()).arg(kicktype); if(charactername == character) { account->ui->messageChannel(this, channelname, message, banned ? MESSAGE_TYPE_KICKBAN : MESSAGE_TYPE_KICK, true, true); channel->removeCharacter(charactername); @@ -1334,7 +1334,7 @@ void FSession::sendChannelMessage(QString channelname, QString message) account->ui->messageSystem(this, QString("Tried to send a message to '%1' but the channel is unknown or has never been joined. Message: %2").arg(channelname).arg(message), MESSAGE_TYPE_FEEDBACK); return; } - if(!channel->isJoined()) { + if(!channel->joined()) { account->ui->messageSystem(this, QString("Tried to send a message to '%1' but you are not currently in the channel. Message: %2").arg(channelname).arg(message), MESSAGE_TYPE_FEEDBACK); return; } @@ -1362,7 +1362,7 @@ void FSession::sendChannelAdvertisement(QString channelname, QString message) account->ui->messageSystem(this, QString("Tried to send a message to '%1' but the channel is unknown or has never been joined. Message: %2").arg(channelname).arg(message), MESSAGE_TYPE_FEEDBACK); return; } - if(!channel->isJoined()) { + if(!channel->joined()) { account->ui->messageSystem(this, QString("Tried to send a message to '%1' but you are not currently in the channel. Message: %2").arg(channelname).arg(message), MESSAGE_TYPE_FEEDBACK); return; } diff --git a/code/flist_messenger/ui/channellistdialog.cpp b/code/flist_messenger/ui/channellistdialog.cpp index 0ed47e2..aa337b8 100644 --- a/code/flist_messenger/ui/channellistdialog.cpp +++ b/code/flist_messenger/ui/channellistdialog.cpp @@ -1,4 +1,5 @@ #include "ui/channellistdialog.h" +#include "flist_global.h" FChannelListModel::FChannelListModel() { @@ -102,27 +103,32 @@ const FChannelSummary &FChannelListModel::byIndex(uint index) const FChannelListSortProxy::FChannelListSortProxy(QObject *parent) : QSortFilterProxyModel(parent), - _showType(FChannelSummary::Unknown) + _showType(FChannelSummary::Unknown), + _showEmpty(false) { setDynamicSortFilter(true); setSortRole(FChannelListModel::SortKeyRole); setFilterRole(FChannelListModel::SortKeyRole); - setFilterKeyColumn(FChannelListModel::colTitle); + setFilterKeyColumn(-1); setSortLocaleAware(true); setSortCaseSensitivity(Qt::CaseInsensitive); setFilterCaseSensitivity(Qt::CaseInsensitive); } +// Prevent displaying lists with zero characters bool FChannelListSortProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { if (!QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) { return false; } - if (_showType == FChannelSummary::Unknown) { return true; } - QModelIndex i = sourceModel()->index(source_row, FChannelListModel::colType, source_parent); + QModelIndex i = sourceModel()->index(source_row, FChannelListModel::colMembers, source_parent); + int nMembers = sourceModel()->data(i, FChannelListModel::SortKeyRole).toInt(); + if ((!_showEmpty) && (nMembers == 0)) { return false; } + if (_showType == FChannelSummary::Unknown) { return true; } + i = sourceModel()->index(source_row, FChannelListModel::colType, source_parent); FChannelSummary::Type t = static_cast(sourceModel()->data(i, FChannelListModel::SortKeyRole).toInt()); - return t == _showType; + return t == _showType; } FChannelSummary::Type FChannelListSortProxy::showType() @@ -136,6 +142,12 @@ void FChannelListSortProxy::setShowType(FChannelSummary::Type t) invalidate(); } +void FChannelListSortProxy::setShowEmpty(bool show) +{ + _showEmpty = show; + invalidate(); +} + FChannelListDialog::FChannelListDialog(FChannelListModel *m, QWidget *parent = 0) : QDialog(parent), Ui::FChannelListDialogUi() { setupUi(this); @@ -202,3 +214,8 @@ void FChannelListDialog::on_chTypePrivate_toggled(bool active) { if(active) datasort->setShowType(FChannelSummary::Private); } + +void FChannelListDialog::on_chShowEmpty_toggled(bool showEmpty) +{ + datasort->setShowEmpty(showEmpty); +} diff --git a/code/flist_messenger/ui/channellistdialog.h b/code/flist_messenger/ui/channellistdialog.h index bea375f..6d96afb 100644 --- a/code/flist_messenger/ui/channellistdialog.h +++ b/code/flist_messenger/ui/channellistdialog.h @@ -63,12 +63,14 @@ class FChannelListSortProxy : public QSortFilterProxyModel FChannelListSortProxy(QObject * parent = 0); FChannelSummary::Type showType(); void setShowType(FChannelSummary::Type t); + void setShowEmpty(bool show); protected: virtual bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const; private: FChannelSummary::Type _showType; + bool _showEmpty; }; class FChannelListDialog : public QDialog, private Ui::FChannelListDialogUi @@ -81,6 +83,7 @@ class FChannelListDialog : public QDialog, private Ui::FChannelListDialogUi FChannelListModel *model(); void setModel(FChannelListModel*); + void setShowEmpty(bool show); signals: void joinRequested(QStringList channels); @@ -93,6 +96,7 @@ class FChannelListDialog : public QDialog, private Ui::FChannelListDialogUi private slots: void on_buttonBox_accepted(); void on_chFilterText_textChanged(const QString&); + void on_chShowEmpty_toggled(bool); void on_chTypeBoth_toggled(bool); void on_chTypePublic_toggled(bool); void on_chTypePrivate_toggled(bool); diff --git a/code/flist_messenger/ui/channellistdialog.ui b/code/flist_messenger/ui/channellistdialog.ui index 8e5e502..a0f6a2e 100644 --- a/code/flist_messenger/ui/channellistdialog.ui +++ b/code/flist_messenger/ui/channellistdialog.ui @@ -6,7 +6,7 @@ 0 0 - 400 + 458 580 @@ -38,7 +38,7 @@ - &Public + Pub&lic true @@ -48,7 +48,7 @@ - P&rivate + Pri&vate @@ -137,11 +137,28 @@ - - - QDialogButtonBox::Close - - + + + + + Show Empty Channels + + + + + + + + 0 + 0 + + + + QDialogButtonBox::Close + + + + @@ -163,8 +180,8 @@ hide() - 199 - 559 + 450 + 572 199