diff --git a/libretroshare/src/grouter/p3grouter.cc b/libretroshare/src/grouter/p3grouter.cc index 77bcdad05..421d2c97c 100644 --- a/libretroshare/src/grouter/p3grouter.cc +++ b/libretroshare/src/grouter/p3grouter.cc @@ -587,7 +587,8 @@ RsGRouterAbstractMsgItem *GRouterDataInfo::addDataChunk(RsGRouterTransactionChun std::cerr << " ERROR: chunk numbering is wrong. Dropping." << std::endl; delete chunk ; delete incoming_data_buffer ; - return NULL; + incoming_data_buffer = NULL ; + return NULL; } incoming_data_buffer->chunk_data = (uint8_t*)realloc((uint8_t*)incoming_data_buffer->chunk_data,incoming_data_buffer->chunk_size + chunk->chunk_size) ; memcpy(&incoming_data_buffer->chunk_data[incoming_data_buffer->chunk_size],chunk->chunk_data,chunk->chunk_size) ; diff --git a/libretroshare/src/gxs/rsdataservice.cc b/libretroshare/src/gxs/rsdataservice.cc index 5661627b3..20d2443bc 100644 --- a/libretroshare/src/gxs/rsdataservice.cc +++ b/libretroshare/src/gxs/rsdataservice.cc @@ -570,7 +570,7 @@ int RsDataService::storeMessage(std::map &msg) std::map::iterator mit = msg.begin(); // start a transaction - mDb->execSQL("BEGIN;"); + mDb->beginTransaction(); for(; mit != msg.end(); ++mit){ @@ -654,7 +654,7 @@ int RsDataService::storeMessage(std::map &msg) } // finish transaction - bool ret = mDb->execSQL("COMMIT;"); + bool ret = mDb->commitTransaction(); for(mit = msg.begin(); mit != msg.end(); ++mit) { @@ -685,7 +685,7 @@ int RsDataService::storeGroup(std::map &grp) std::map::iterator sit = grp.begin(); // begin transaction - mDb->execSQL("BEGIN;"); + mDb->beginTransaction(); for(; sit != grp.end(); ++sit) { @@ -769,7 +769,7 @@ int RsDataService::storeGroup(std::map &grp) } } // finish transaction - bool ret = mDb->execSQL("COMMIT;"); + bool ret = mDb->commitTransaction(); for(sit = grp.begin(); sit != grp.end(); ++sit) { @@ -791,7 +791,7 @@ int RsDataService::updateGroup(std::map &grp) std::map::iterator sit = grp.begin(); // begin transaction - mDb->execSQL("BEGIN;"); + mDb->beginTransaction(); for(; sit != grp.end(); ++sit) { @@ -858,7 +858,7 @@ int RsDataService::updateGroup(std::map &grp) mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpPtr->grpId.toStdString() + "'", cv); } // finish transaction - bool ret = mDb->execSQL("COMMIT;"); + bool ret = mDb->commitTransaction(); for(sit = grp.begin(); sit != grp.end(); ++sit) { @@ -877,7 +877,7 @@ int RsDataService::updateGroupKeys(const RsGxsGroupId& grpId,const RsTlvSecurity RsStackMutex stack(mDbMutex); // begin transaction - mDb->execSQL("BEGIN;"); + mDb->beginTransaction(); /*! * STORE key set @@ -895,7 +895,7 @@ int RsDataService::updateGroupKeys(const RsGxsGroupId& grpId,const RsTlvSecurity mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpId.toStdString() + "'", cv); // finish transaction - return mDb->execSQL("COMMIT;"); + return mDb->commitTransaction(); } bool RsDataService::validSize(RsNxsGrp* grp) const @@ -1608,7 +1608,7 @@ int RsDataService::retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std bool RsDataService::locked_updateMessageEntries(const MsgUpdates& updates) { // start a transaction - bool ret = mDb->execSQL("BEGIN;"); + bool ret = mDb->beginTransaction(); MsgUpdates::const_iterator mit = updates.begin(); @@ -1627,7 +1627,7 @@ bool RsDataService::locked_updateMessageEntries(const MsgUpdates& updates) } } - ret &= mDb->execSQL("COMMIT;"); + ret &= mDb->commitTransaction(); return ret; } @@ -1635,7 +1635,7 @@ bool RsDataService::locked_updateMessageEntries(const MsgUpdates& updates) bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds) { // start a transaction - bool ret = mDb->execSQL("BEGIN;"); + bool ret = mDb->beginTransaction(); GxsMsgReq::const_iterator mit = msgIds.begin(); @@ -1653,7 +1653,7 @@ bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds) } } - ret &= mDb->execSQL("COMMIT;"); + ret &= mDb->commitTransaction(); return ret; } @@ -1661,7 +1661,7 @@ bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds) bool RsDataService::locked_removeGroupEntries(const std::vector& grpIds) { // start a transaction - bool ret = mDb->execSQL("BEGIN;"); + bool ret = mDb->beginTransaction(); std::vector::const_iterator vit = grpIds.begin(); @@ -1672,7 +1672,7 @@ bool RsDataService::locked_removeGroupEntries(const std::vector& g mDb->sqlDelete(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", ""); } - ret &= mDb->execSQL("COMMIT;"); + ret &= mDb->commitTransaction(); return ret; } diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 6816d9476..f584e81af 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -908,7 +908,7 @@ int RsGenExchange::validateGrp(RsNxsGrp* grp) PrivacyBitPos pos = GRP_OPTION_BITS; // Check required permissions, and allow them to sign it - if they want too - as well! - if (!(metaData.mAuthorId.isNull()) || checkAuthenFlag(pos, author_flag)) + if ((!metaData.mAuthorId.isNull()) || checkAuthenFlag(pos, author_flag)) { needIdentitySign = true; std::cerr << "Needs Identity sign! (Service Flags)"; diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index de30910fb..35007db99 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1897,7 +1897,7 @@ bool pqissl::cansend(uint32_t usec) if(sockfd == -1) { - std::cerr << "pqissl::moretoread(): socket is invalid or closed." << std::endl; + std::cerr << "pqissl::cansend(): socket is invalid or closed." << std::endl; return 0 ; } diff --git a/libretroshare/src/util/retrodb.cc b/libretroshare/src/util/retrodb.cc index 368c5240e..b6633c3a5 100644 --- a/libretroshare/src/util/retrodb.cc +++ b/libretroshare/src/util/retrodb.cc @@ -264,6 +264,32 @@ std::string RetroDb::getKey() const return mKey; } +bool RetroDb::beginTransaction() +{ + if (!isOpen()) { + return false; + } + + return execSQL("BEGIN;"); +} + +bool RetroDb::commitTransaction() +{ + if (!isOpen()) { + return false; + } + + return execSQL("COMMIT;"); +} +bool RetroDb::rollbackTransaction() +{ + if (!isOpen()) { + return false; + } + + return execSQL("ROLLBACK;"); +} + bool RetroDb::execSQL_bind(const std::string &query, std::list ¶mBindings){ // prepare statement @@ -531,6 +557,43 @@ bool RetroDb::sqlUpdate(const std::string &tableName, std::string whereClause, c return execSQL_bind(sqlQuery, paramBindings); } +bool RetroDb::tableExists(const std::string &tableName) +{ + if (!isOpen()) { + return false; + } + + std::string sqlQuery = "PRAGMA table_info(" + tableName + ");"; + + bool result = false; + sqlite3_stmt* stmt = NULL; + + int rc = sqlite3_prepare_v2(mDb, sqlQuery.c_str(), sqlQuery.length(), &stmt, NULL); + if (rc == SQLITE_OK) { + rc = sqlite3_step(stmt); + switch (rc) { + case SQLITE_ROW: + result = true; + break; + case SQLITE_DONE: + break; + default: + std::cerr << "RetroDb::tableExists(): Error executing statement (code: " << rc << ")" + << std::endl; + return false; + } + } else { + std::cerr << "RetroDb::tableExists(): Error preparing statement\n"; + std::cerr << "Error code: " << sqlite3_errmsg(mDb) + << std::endl; + } + + if (stmt) { + sqlite3_finalize(stmt); + } + + return result; +} /********************** RetroCursor ************************/ diff --git a/libretroshare/src/util/retrodb.h b/libretroshare/src/util/retrodb.h index c0e2f8db6..8b79c0017 100644 --- a/libretroshare/src/util/retrodb.h +++ b/libretroshare/src/util/retrodb.h @@ -38,8 +38,6 @@ #include "contentvalue.h" - - class RetroCursor; /*! @@ -90,7 +88,23 @@ public: /* modifying db */ public: + /*! + * Start transaction + * @return true/false + */ + bool beginTransaction(); + /*! + * Commit transaction + * @return true/false + */ + bool commitTransaction(); + + /*! + * Rollback transaction + * @return true/false + */ + bool rollbackTransaction(); /*! * To a make query which do not return a result \n @@ -153,22 +167,13 @@ public: */ void vacuum(); - /*! - * Build the "VALUE" part of an insertiong sql query - * @param parameter contains place holder query - * @param paramBindings + * Check if table exist in database + * @param tableName table to check + * @return true/false */ - void buildInsertQueryValue(const std::map keyMap, const ContentValue& cv, - std::string& parameter, std::list& paramBindings); + bool tableExists(const std::string& tableName); - /*! - * Build the "VALUE" part of an insertiong sql query - * @param parameter contains place holder query - * @param paramBindings - */ - void buildUpdateQueryValue(const std::map keyMap, const ContentValue& cv, - std::string& parameter, std::list& paramBindings); public: static const int OPEN_READONLY; @@ -179,6 +184,22 @@ private: bool execSQL_bind(const std::string &query, std::list& blobs); + /*! + * Build the "VALUE" part of an insertiong sql query + * @param parameter contains place holder query + * @param paramBindings + */ + void buildInsertQueryValue(const std::map keyMap, const ContentValue& cv, + std::string& parameter, std::list& paramBindings); + + /*! + * Build the "VALUE" part of an insertiong sql query + * @param parameter contains place holder query + * @param paramBindings + */ + void buildUpdateQueryValue(const std::map keyMap, const ContentValue& cv, + std::string& parameter, std::list& paramBindings); + private: sqlite3* mDb; diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 95ac04807..2bbcedb86 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -79,7 +79,6 @@ #define IMAGE_GROUP24 ":/images/user/group24.png" #define COLUMN_DATA 0 // column for storing the userdata id -#define COLUMN_SORT COLUMN_NAME // column for sorting #define ROLE_ID Qt::UserRole #define ROLE_STANDARD Qt::UserRole + 1 @@ -130,16 +129,19 @@ FriendList::FriendList(QWidget *parent) : connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool))); connect(ui->actionShowGroups, SIGNAL(triggered(bool)), this, SLOT(setShowGroups(bool))); - connect(ui->actionSortByName, SIGNAL(triggered()), this, SLOT(setSortByName())); - connect(ui->actionSortByState, SIGNAL(triggered()), this, SLOT(setSortByState())); - connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString))); ui->filterLineEdit->setPlaceholderText(tr("Search")) ; ui->filterLineEdit->showFilterIcon(); + mActionSortByState = new QAction(tr("Sort by state"), this); + mActionSortByState->setCheckable(true); + connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(sortByState(bool))); + ui->peerTreeWidget->addHeaderContextMenuAction(mActionSortByState); + /* Set sort */ - setSortMode(SORT_MODE_NAME); + sortByColumn(COLUMN_NAME, Qt::AscendingOrder); + sortByState(false); // workaround for Qt bug, should be solved in next Qt release 4.7.0 // http://bugreports.qt.nokia.com/browse/QTBUG-8270 @@ -191,7 +193,7 @@ void FriendList::addToolButton(QToolButton *toolButton) void FriendList::processSettings(bool load) { // state of peer tree - ui->peerTreeWidget->setSettingsVersion(1); + ui->peerTreeWidget->setSettingsVersion(2); ui->peerTreeWidget->processSettings(load); if (load) { @@ -206,7 +208,7 @@ void FriendList::processSettings(bool load) setShowGroups(Settings->value("showGroups", mShowGroups).toBool()); // sort - setSortMode((SortMode) Settings->value("sortMode", SORT_MODE_NAME).toInt()); + sortByState(Settings->value("sortByState", isSortByState()).toBool()); // open groups int arrayIndex = Settings->beginReadArray("Groups"); @@ -224,7 +226,7 @@ void FriendList::processSettings(bool load) Settings->setValue("showGroups", mShowGroups); // sort - Settings->setValue("sortMode", sortMode()); + Settings->setValue("sortByState", isSortByState()); // open groups Settings->beginWriteArray("Groups"); @@ -687,9 +689,11 @@ void FriendList::insertPeers() groupItem->setData(COLUMN_DATA, ROLE_STANDARD, (groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? true : false); /* Sort data */ - groupItem->setData(COLUMN_SORT, ROLE_SORT_GROUP, 1); - groupItem->setData(COLUMN_SORT, ROLE_SORT_STANDARD_GROUP, (groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? 0 : 1); - groupItem->setData(COLUMN_SORT, ROLE_SORT_STATE, 0); + for (int i = 0; i < columnCount; ++i) { + groupItem->setData(i, ROLE_SORT_GROUP, 1); + groupItem->setData(i, ROLE_SORT_STANDARD_GROUP, (groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? 0 : 1); + groupItem->setData(i, ROLE_SORT_STATE, 0); + } } else { // remove all gpg items that are not more assigned int childCount = groupItem->childCount(); @@ -786,9 +790,10 @@ void FriendList::insertPeers() gpgItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.gpg_id.toStdString())); /* Sort data */ - gpgItem->setData(COLUMN_SORT, ROLE_SORT_GROUP, 2); - // show first the standard groups, than the user groups - gpgItem->setData(COLUMN_SORT, ROLE_SORT_STANDARD_GROUP, 1); + for (int i = 0; i < columnCount; ++i) { + gpgItem->setData(i, ROLE_SORT_GROUP, 2); + gpgItem->setData(i, ROLE_SORT_STANDARD_GROUP, 1); + } } ++availableCount; @@ -860,8 +865,10 @@ void FriendList::insertPeers() gpgItem->addChild(sslItem); /* Sort data */ - sslItem->setData(COLUMN_SORT, ROLE_SORT_GROUP, 2); - sslItem->setData(COLUMN_SORT, ROLE_SORT_STANDARD_GROUP, 1); + for (int i = 0; i < columnCount; ++i) { + sslItem->setData(i, ROLE_SORT_GROUP, 2); + sslItem->setData(i, ROLE_SORT_STANDARD_GROUP, 1); + } } /* not displayed, used to find back the item */ @@ -879,6 +886,7 @@ void FriendList::insertPeers() /* last contact */ QDateTime sslLastContact = QDateTime::fromTime_t(sslDetail.lastConnect); sslItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, QVariant(sslLastContact)); + sslItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT_NAME, QVariant(sslLastContact)); if (sslLastContact > bestLastContact) { bestLastContact = sslLastContact; } @@ -886,6 +894,7 @@ void FriendList::insertPeers() /* IP */ QString sslIP = (sslDetail.state & RS_PEER_STATE_CONNECTED) ? StatusDefs::connectStateIpString(sslDetail) : QString("---"); sslItem->setText(COLUMN_IP, sslIP); + sslItem->setData(COLUMN_IP, ROLE_SORT_NAME, sslIP); /* change color and icon */ QPixmap sslOverlayIcon; @@ -1044,10 +1053,11 @@ void FriendList::insertPeers() sslItem->setIcon(COLUMN_NAME, createAvatar(sslAvatar, sslOverlayIcon)); /* Sort data */ - sslItem->setData(COLUMN_SORT, ROLE_SORT_NAME, sslName); - sslItem->setData(COLUMN_SORT, ROLE_SORT_STATE, peerState); + sslItem->setData(COLUMN_NAME, ROLE_SORT_NAME, sslName); for (int i = 0; i < columnCount; ++i) { + sslItem->setData(i, ROLE_SORT_STATE, peerState); + sslItem->setTextColor(i, sslColor); sslItem->setFont(i, sslFont); } @@ -1147,13 +1157,16 @@ void FriendList::insertPeers() } gpgItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, showInfoAtGpgItem ? QVariant(bestLastContact) : ""); + gpgItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT_NAME, showInfoAtGpgItem ? QVariant(bestLastContact) : ""); gpgItem->setText(COLUMN_IP, showInfoAtGpgItem ? bestIP : ""); + gpgItem->setData(COLUMN_IP, ROLE_SORT_NAME, showInfoAtGpgItem ? bestIP : ""); /* Sort data */ - gpgItem->setData(COLUMN_SORT, ROLE_SORT_NAME, gpgName); - gpgItem->setData(COLUMN_SORT, ROLE_SORT_STATE, bestPeerState); + gpgItem->setData(COLUMN_NAME, ROLE_SORT_NAME, gpgName); for (int i = 0; i < columnCount; ++i) { + gpgItem->setData(i, ROLE_SORT_STATE, bestPeerState); + gpgItem->setTextColor(i, gpgColor); gpgItem->setFont(i, gpgFont); } @@ -1173,7 +1186,7 @@ void FriendList::insertPeers() groupItem->setText(COLUMN_NAME, QString("%1 (%2/%3)").arg(groupName).arg(onlineCount).arg(availableCount)); /* Sort data */ - groupItem->setData(COLUMN_SORT, ROLE_SORT_NAME, groupName); + groupItem->setData(COLUMN_NAME, ROLE_SORT_NAME, groupName); } } @@ -1199,7 +1212,7 @@ void FriendList::insertPeers() openPeers = NULL; } - ui->peerTreeWidget->sortItems(COLUMN_SORT, Qt::AscendingOrder); + ui->peerTreeWidget->resort(); } /** @@ -1745,6 +1758,11 @@ void FriendList::setColumnVisible(Column column, bool visible) peerTreeColumnVisibleChanged(column, visible); } +void FriendList::sortByColumn(Column column, Qt::SortOrder sortOrder) +{ + ui->peerTreeWidget->sortByColumn(column, sortOrder); +} + void FriendList::peerTreeColumnVisibleChanged(int /*column*/, bool visible) { if (visible) { @@ -1771,49 +1789,30 @@ void FriendList::setShowState(bool show) } } -void FriendList::setSortByName() +void FriendList::sortByState(bool sort) { - setSortMode(SORT_MODE_NAME); -} + int columnCount = ui->peerTreeWidget->columnCount(); + for (int i = 0; i < columnCount; ++i) { + mCompareRole->setRole(i, ROLE_SORT_GROUP); + mCompareRole->addRole(i, ROLE_SORT_STANDARD_GROUP); -void FriendList::setSortByState() -{ - setSortMode(SORT_MODE_STATE); -} - -void FriendList::setSortMode(SortMode sortMode) -{ - // Add changes also in FriendList::sortMode - mCompareRole->setRole(COLUMN_SORT, ROLE_SORT_GROUP); - mCompareRole->addRole(COLUMN_SORT, ROLE_SORT_STANDARD_GROUP); - - switch (sortMode) { - case SORT_MODE_STATE: - mCompareRole->addRole(COLUMN_SORT, ROLE_SORT_STATE); - mCompareRole->addRole(COLUMN_SORT, ROLE_SORT_NAME); - break; - default: // SORT_MODE_NAME - mCompareRole->addRole(COLUMN_SORT, ROLE_SORT_NAME); - mCompareRole->addRole(COLUMN_SORT, ROLE_SORT_STATE); - } - - ui->peerTreeWidget->sortItems(COLUMN_SORT, Qt::AscendingOrder); -} - -FriendList::SortMode FriendList::sortMode() -{ - QList roles; - mCompareRole->findRoles(COLUMN_SORT, roles); - if (roles.count() == 4) { - switch (roles.at(2)) { - case ROLE_SORT_NAME: - return SORT_MODE_NAME; - case ROLE_SORT_STATE: - return SORT_MODE_STATE; + if (sort) { + mCompareRole->addRole(i, ROLE_SORT_STATE); + mCompareRole->addRole(i, ROLE_SORT_NAME); + } else { + mCompareRole->addRole(i, ROLE_SORT_NAME); + mCompareRole->addRole(i, ROLE_SORT_STATE); } } - return SORT_MODE_NAME; + mActionSortByState->setChecked(sort); + + ui->peerTreeWidget->resort(); +} + +bool FriendList::isSortByState() +{ + return mActionSortByState->isChecked(); } void FriendList::setShowGroups(bool show) @@ -1876,14 +1875,6 @@ void FriendList::createDisplayMenu() QMenu *displayMenu = new QMenu(this); connect(displayMenu, SIGNAL(aboutToShow()), this, SLOT(updateMenu())); - QActionGroup *actionGroup = new QActionGroup(displayMenu); - - QMenu *menu = displayMenu->addMenu(tr("Sort by")); - menu->addAction(ui->actionSortByName); - ui->actionSortByName->setActionGroup(actionGroup); - menu->addAction(ui->actionSortByState); - ui->actionSortByState->setActionGroup(actionGroup); - displayMenu->addAction(ui->actionHideOfflineFriends); displayMenu->addAction(ui->actionShowState); displayMenu->addAction(ui->actionShowGroups); @@ -1896,14 +1887,4 @@ void FriendList::updateMenu() ui->actionHideOfflineFriends->setChecked(mHideUnconnected); ui->actionShowState->setChecked(mShowState); ui->actionShowGroups->setChecked(mShowGroups); - ui->actionSortByName->setChecked(true); - - switch (sortMode()) { - case SORT_MODE_NAME: - ui->actionSortByName->setChecked(true); - break; - case SORT_MODE_STATE: - ui->actionSortByState->setChecked(true); - break; - } } diff --git a/retroshare-gui/src/gui/common/FriendList.h b/retroshare-gui/src/gui/common/FriendList.h index 5522c775f..96cd1d3e0 100644 --- a/retroshare-gui/src/gui/common/FriendList.h +++ b/retroshare-gui/src/gui/common/FriendList.h @@ -56,12 +56,6 @@ public: COLUMN_IP = 2 }; - enum SortMode - { - SORT_MODE_NAME = 1, - SORT_MODE_STATE = 2 - }; - public: explicit FriendList(QWidget *parent = 0); ~FriendList(); @@ -79,8 +73,8 @@ public: virtual void updateDisplay(); void setColumnVisible(Column column, bool visible); - void setSortMode(SortMode sortMode); - SortMode sortMode(); + void sortByColumn(Column column, Qt::SortOrder sortOrder); + bool isSortByState(); QColor textColorGroup() const { return mTextColorGroup; } QColor textColorStatusOffline() const { return mTextColorStatus[RS_STATUS_OFFLINE]; } @@ -98,8 +92,7 @@ public: public slots: void filterItems(const QString &text); - void setSortByName(); - void setSortByState(); + void sortByState(bool sort); void setShowGroups(bool show); void setHideUnconnected(bool hidden); @@ -116,6 +109,7 @@ protected: private: Ui::FriendList *ui; RSTreeWidgetItemCompareRole *mCompareRole; + QAction *mActionSortByState; // Settings for peer list display bool mShowGroups; diff --git a/retroshare-gui/src/gui/common/FriendList.ui b/retroshare-gui/src/gui/common/FriendList.ui index fa4a44223..0322cb1a8 100644 --- a/retroshare-gui/src/gui/common/FriendList.ui +++ b/retroshare-gui/src/gui/common/FriendList.ui @@ -75,6 +75,9 @@ Qt::CustomContextMenu + + true + true @@ -116,28 +119,6 @@ Hide Offline Friends - - - true - - - Name - - - Sort by Name - - - - - true - - - State - - - Sort by State - - true diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index 19b8c63c6..3cc3ff3d0 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -21,6 +21,7 @@ ****************************************************************/ #include +#include #include "FriendSelectionWidget.h" #include "ui_FriendSelectionWidget.h" #include "gui/gxs/GxsIdDetails.h" @@ -44,8 +45,11 @@ #define IDDIALOG_IDLIST 1 -#define ROLE_ID Qt::UserRole -#define ROLE_SORT Qt::UserRole + 1 +#define ROLE_ID Qt::UserRole +#define ROLE_SORT_GROUP Qt::UserRole + 1 +#define ROLE_SORT_STANDARD_GROUP Qt::UserRole + 2 +#define ROLE_SORT_NAME Qt::UserRole + 3 +#define ROLE_SORT_STATE Qt::UserRole + 4 #define IMAGE_GROUP16 ":/images/user/group16.png" #define IMAGE_FRIENDINFO ":/images/peerdetails_16x16.png" @@ -94,15 +98,17 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) connect(ui->friendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint))); connect(ui->friendList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int))); connect(ui->friendList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*,int))); - connect(ui->selectAll_PB, SIGNAL(clicked()), this, SLOT(selectAll())); - connect(ui->deselectAll_PB, SIGNAL(clicked()), this, SLOT(deselectAll())); + connect(ui->friendList, SIGNAL(itemSelectionChanged()), this, SIGNAL(itemSelectionChanged())); connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString))); connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged(int))); connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int))); mCompareRole = new RSTreeWidgetItemCompareRole; - mCompareRole->setRole(COLUMN_NAME, ROLE_SORT); + mActionSortByState = new QAction(tr("Sort by state"), this); + mActionSortByState->setCheckable(true); + connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(sortByState(bool))); + ui->friendList->addHeaderContextMenuAction(mActionSortByState); /* initialize list */ ui->friendList->setColumnCount(COLUMN_COUNT); @@ -110,6 +116,7 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) /* sort list by name ascending */ ui->friendList->sortItems(COLUMN_NAME, Qt::AscendingOrder); + sortByState(false); ui->filterLineEdit->setPlaceholderText(tr("Search Friends")); ui->filterLineEdit->showFilterIcon(); @@ -156,17 +163,6 @@ void FriendSelectionWidget::setModus(Modus modus) break; } - if(modus == MODUS_CHECK) - { - ui->selectAll_PB->setHidden(false) ; - ui->deselectAll_PB->setHidden(false) ; - } - else - { - ui->selectAll_PB->setHidden(true) ; - ui->deselectAll_PB->setHidden(true) ; - } - fillList(); } @@ -216,8 +212,12 @@ static void initSslItem(QTreeWidgetItem *item, const RsPeerDetails &detail, cons } item->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(state))); - item->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.id.toStdString())); - item->setData(COLUMN_DATA, ROLE_SORT, "2 " + name); + item->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.id.toStdString())); + + item->setData(COLUMN_NAME, ROLE_SORT_GROUP, 1); + item->setData(COLUMN_NAME, ROLE_SORT_STANDARD_GROUP, 0); + item->setData(COLUMN_NAME, ROLE_SORT_STATE, (state != (int) RS_STATUS_OFFLINE) ? 0 : 1); + item->setData(COLUMN_NAME, ROLE_SORT_NAME, name); } void FriendSelectionWidget::fillList() @@ -349,7 +349,11 @@ void FriendSelectionWidget::secured_fillList() QString groupName = GroupDefs::name(*groupInfo); groupItem->setText(COLUMN_NAME, groupName); - groupItem->setData(COLUMN_DATA, ROLE_SORT, ((groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? "0 " : "1 ") + groupName); + + groupItem->setData(COLUMN_NAME, ROLE_SORT_GROUP, 0); + groupItem->setData(COLUMN_NAME, ROLE_SORT_STANDARD_GROUP, (groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? 0 : 1); + groupItem->setData(COLUMN_NAME, ROLE_SORT_STATE, 0); + groupItem->setData(COLUMN_NAME, ROLE_SORT_NAME, groupName); if (mListModus == MODUS_CHECK) { groupItem->setCheckState(0, Qt::Unchecked); @@ -411,8 +415,12 @@ void FriendSelectionWidget::secured_fillList() gpgItem->setFlags(Qt::ItemIsUserCheckable | gpgItem->flags()); gpgItem->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(state))); - gpgItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.gpg_id.toStdString())); - gpgItem->setData(COLUMN_DATA, ROLE_SORT, "2 " + name); + gpgItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.gpg_id.toStdString())); + + gpgItem->setData(COLUMN_NAME, ROLE_SORT_GROUP, 1); + gpgItem->setData(COLUMN_NAME, ROLE_SORT_STANDARD_GROUP, 0); + gpgItem->setData(COLUMN_NAME, ROLE_SORT_STATE, (state != (int) RS_STATUS_OFFLINE) ? 0 : 1); + gpgItem->setData(COLUMN_NAME, ROLE_SORT_NAME, name); if (mListModus == MODUS_CHECK) { gpgItem->setCheckState(0, Qt::Unchecked); @@ -542,7 +550,12 @@ void FriendSelectionWidget::secured_fillList() gxsItem->setFlags(Qt::ItemIsUserCheckable | gxsItem->flags()); gxsItem->setIcon(COLUMN_NAME, identicon); gxsItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.mId.toStdString())); - gxsItem->setData(COLUMN_DATA, ROLE_SORT, "2 " + name); + + gxsItem->setData(COLUMN_NAME, ROLE_SORT_GROUP, 1); + gxsItem->setData(COLUMN_NAME, ROLE_SORT_STANDARD_GROUP, 0); +//TODO: online state for gxs items + gxsItem->setData(COLUMN_NAME, ROLE_SORT_STATE, 1); + gxsItem->setData(COLUMN_NAME, ROLE_SORT_NAME, name); if (mListModus == MODUS_CHECK) gxsItem->setCheckState(0, Qt::Unchecked); @@ -573,6 +586,8 @@ void FriendSelectionWidget::secured_fillList() mInFillList = false; + ui->friendList->resort(); + emit contentChanged(); } void FriendSelectionWidget::updateDisplay(bool) @@ -658,6 +673,7 @@ void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status) switch (idTypeFromItem(item)) { case IDTYPE_NONE: case IDTYPE_GROUP: + case IDTYPE_GXS: break; case IDTYPE_GPG: { @@ -672,6 +688,8 @@ void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status) item->setTextColor(COLUMN_NAME, color); item->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(gpgStatus))); + item->setData(COLUMN_NAME, ROLE_SORT_STATE, (gpgStatus != (int) RS_STATUS_OFFLINE) ? 0 : 1); + bFoundGPG = true; } } @@ -689,6 +707,8 @@ void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status) item->setTextColor(COLUMN_NAME, color); item->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(status))); + item->setData(COLUMN_NAME, ROLE_SORT_STATE, (status != (int) RS_STATUS_OFFLINE) ? 0 : 1); + bFoundSSL = true; } } @@ -714,11 +734,48 @@ void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status) } } } + + ui->friendList->resort(); } -void FriendSelectionWidget::contextMenuRequested(const QPoint &pos) +void FriendSelectionWidget::addContextMenuAction(QAction *action) { - emit customContextMenuRequested(pos); + mContextMenuActions.push_back(action); +} + +void FriendSelectionWidget::contextMenuRequested(const QPoint &/*pos*/) +{ + QMenu contextMenu(this); + + if (mListModus == MODUS_CHECK) { + contextMenu.addAction(QIcon(), tr("Mark all"), this, SLOT(selectAll())); + contextMenu.addAction(QIcon(), tr("Mark none"), this, SLOT(deselectAll())); + } + + if (!mContextMenuActions.isEmpty()) { + bool addSeparator = false; + if (!contextMenu.isEmpty()) { + // Check for visible action + foreach (QAction *action, mContextMenuActions) { + if (action->isVisible()) { + addSeparator = true; + break; + } + } + } + + if (addSeparator) { + contextMenu.addSeparator(); + } + + contextMenu.addActions(mContextMenuActions); + } + + if (contextMenu.isEmpty()) { + return; + } + + contextMenu.exec(QCursor::pos()); } void FriendSelectionWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/) @@ -1030,3 +1087,25 @@ std::string FriendSelectionWidget::idFromItem(QTreeWidgetItem *item) return item->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); } +void FriendSelectionWidget::sortByState(bool sort) +{ + mCompareRole->setRole(COLUMN_NAME, ROLE_SORT_GROUP); + mCompareRole->addRole(COLUMN_NAME, ROLE_SORT_STANDARD_GROUP); + + if (sort) { + mCompareRole->addRole(COLUMN_NAME, ROLE_SORT_STATE); + mCompareRole->addRole(COLUMN_NAME, ROLE_SORT_NAME); + } else { + mCompareRole->addRole(COLUMN_NAME, ROLE_SORT_NAME); + mCompareRole->addRole(COLUMN_NAME, ROLE_SORT_STATE); + } + + mActionSortByState->setChecked(sort); + + ui->friendList->resort(); +} + +bool FriendSelectionWidget::isSortByState() +{ + return mActionSortByState->isChecked(); +} diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.h b/retroshare-gui/src/gui/common/FriendSelectionWidget.h index 92bd6d0fc..22e571808 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.h +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.h @@ -80,6 +80,8 @@ public: int addColumn(const QString &title); void start(); + bool isSortByState(); + int selectedItemCount(); std::string selectedId(IdType &idType); @@ -109,6 +111,9 @@ public: void setTextColorOnline(QColor color) { mTextColorOnline = color; } + // Add QAction to context menu (action won't be deleted) + void addContextMenuAction(QAction *action); + protected: void changeEvent(QEvent *e); @@ -118,9 +123,12 @@ protected: signals: void itemAdded(int idType, const QString &id, QTreeWidgetItem *item); void contentChanged(); - void customContextMenuRequested(const QPoint &pos); void doubleClicked(int idType, const QString &id); void itemChanged(int idType, const QString &id, QTreeWidgetItem *item, int column); + void itemSelectionChanged(); + +public slots: + void sortByState(bool sort); private slots: void groupsChanged(int type); @@ -142,6 +150,7 @@ private: void requestGXSIdList() ; +private: bool mStarted; RSTreeWidgetItemCompareRole *mCompareRole; Modus mListModus; @@ -150,6 +159,7 @@ private: bool mInGpgItemChanged; bool mInSslItemChanged; bool mInFillList; + QAction *mActionSortByState; /* Color definitions (for standard see qss.default) */ QColor mTextColorOnline; @@ -160,6 +170,7 @@ private: std::vector gxsIds ; TokenQueue *mIdQueue ; + QList mContextMenuActions; }; Q_DECLARE_OPERATORS_FOR_FLAGS(FriendSelectionWidget::ShowTypes) diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.ui b/retroshare-gui/src/gui/common/FriendSelectionWidget.ui index 2ad0972b0..23d98c9b6 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.ui +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.ui @@ -26,24 +26,10 @@ - - - - All - - - - - - - None - - - - + 20 @@ -80,6 +66,11 @@ QLineEdit
gui/common/LineEditClear.h
+ + RSTreeWidget + QTreeWidget +
gui/common/RSTreeWidget.h
+
diff --git a/retroshare-gui/src/gui/common/RSTreeWidget.cpp b/retroshare-gui/src/gui/common/RSTreeWidget.cpp index dece380df..9199e832e 100644 --- a/retroshare-gui/src/gui/common/RSTreeWidget.cpp +++ b/retroshare-gui/src/gui/common/RSTreeWidget.cpp @@ -31,6 +31,10 @@ RSTreeWidget::RSTreeWidget(QWidget *parent) : QTreeWidget(parent) { mEnableColumnCustomize = false; mSettingsVersion = 0; // disabled + + QHeaderView *h = header(); + h->setContextMenuPolicy(Qt::CustomContextMenu); + connect(h, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint))); } void RSTreeWidget::setPlaceholderText(const QString &text) @@ -153,16 +157,6 @@ void RSTreeWidget::enableColumnCustomize(bool customizable) } mEnableColumnCustomize = customizable; - - QHeaderView *h = header(); - - if (mEnableColumnCustomize) { - h->setContextMenuPolicy(Qt::CustomContextMenu); - connect(h, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint))); - } else { - h->setContextMenuPolicy(Qt::DefaultContextMenu); - disconnect(h, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint))); - } } void RSTreeWidget::setColumnCustomizable(int column, bool customizable) @@ -170,25 +164,51 @@ void RSTreeWidget::setColumnCustomizable(int column, bool customizable) mColumnCustomizable[column] = customizable; } +void RSTreeWidget::addHeaderContextMenuAction(QAction *action) +{ + mHeaderContextMenuActions.push_back(action); +} + void RSTreeWidget::headerContextMenuRequested(const QPoint &pos) { - if (!mEnableColumnCustomize) { - return; - } - QMenu contextMenu(this); - QTreeWidgetItem *item = headerItem(); - int columnCount = item->columnCount(); - for (int column = 0; column < columnCount; ++column) { - QMap::const_iterator it = mColumnCustomizable.find(column); - if (it != mColumnCustomizable.end() && *it == false) { - continue; + if (mEnableColumnCustomize) { + QTreeWidgetItem *item = headerItem(); + int columnCount = item->columnCount(); + for (int column = 0; column < columnCount; ++column) { + QMap::const_iterator it = mColumnCustomizable.find(column); + if (it != mColumnCustomizable.end() && *it == false) { + continue; + } + QAction *action = contextMenu.addAction(QIcon(), item->text(column), this, SLOT(columnVisible())); + action->setCheckable(true); + action->setData(column); + action->setChecked(!isColumnHidden(column)); } - QAction *action = contextMenu.addAction(QIcon(), item->text(column), this, SLOT(columnVisible())); - action->setCheckable(true); - action->setData(column); - action->setChecked(!isColumnHidden(column)); + } + + if (!mHeaderContextMenuActions.isEmpty()) { + bool addSeparator = false; + if (!contextMenu.isEmpty()) { + // Check for visible action + foreach (QAction *action, mHeaderContextMenuActions) { + if (action->isVisible()) { + addSeparator = true; + break; + } + } + } + + if (addSeparator) { + contextMenu.addSeparator(); + } + + contextMenu.addActions(mHeaderContextMenuActions); + } + + if (contextMenu.isEmpty()) { + return; } contextMenu.exec(mapToGlobal(pos)); @@ -207,3 +227,10 @@ void RSTreeWidget::columnVisible() emit columnVisibleChanged(column, visible); } + +void RSTreeWidget::resort() +{ + if (isSortingEnabled()) { + sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder()); + } +} diff --git a/retroshare-gui/src/gui/common/RSTreeWidget.h b/retroshare-gui/src/gui/common/RSTreeWidget.h index 91b75b810..7756bdea0 100644 --- a/retroshare-gui/src/gui/common/RSTreeWidget.h +++ b/retroshare-gui/src/gui/common/RSTreeWidget.h @@ -43,6 +43,11 @@ public: void enableColumnCustomize(bool customizable); void setColumnCustomizable(int column, bool customizable); + void resort(); + + // Add QAction to context menu (action won't be deleted) + void addHeaderContextMenuAction(QAction *action); + signals: void signalMouseMiddleButtonClicked(QTreeWidgetItem *item); void columnVisibleChanged(int column, bool visible); @@ -63,6 +68,7 @@ private: bool mEnableColumnCustomize; quint32 mSettingsVersion; QMap mColumnCustomizable; + QList mHeaderContextMenuActions; }; #endif diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 08ff494ea..16c58a20c 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -128,6 +128,7 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags) setupEditActions(); setupViewActions(); setupInsertActions(); + setupContactActions(); m_compareRole = new RSTreeWidgetItemCompareRole; m_compareRole->setRole(COLUMN_CONTACT_NAME, ROLE_CONTACT_SORT); @@ -210,8 +211,8 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags) connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int))); connect(ui.friendSelectionWidget, SIGNAL(contentChanged()), this, SLOT(buildCompleter())); - connect(ui.friendSelectionWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuMsgSendList(QPoint))); connect(ui.friendSelectionWidget, SIGNAL(doubleClicked(int,QString)), this, SLOT(addTo())); + connect(ui.friendSelectionWidget, SIGNAL(itemSelectionChanged()), this, SLOT(friendSelectionChanged())); /* hide the Tree +/- */ ui.msgFileList -> setRootIsDecorated( false ); @@ -698,35 +699,6 @@ void MessageComposer::contextMenuFileList(QPoint) contextMnu.exec(QCursor::pos()); } -void MessageComposer::contextMenuMsgSendList(QPoint) -{ - QMenu contextMnu(this); - - int selectedCount = ui.friendSelectionWidget->selectedItemCount(); - - FriendSelectionWidget::IdType idType; - ui.friendSelectionWidget->selectedId(idType); - - QAction *action = contextMnu.addAction(QIcon(), tr("Add to \"To\""), this, SLOT(addTo())); - action->setEnabled(selectedCount); - action = contextMnu.addAction(QIcon(), tr("Add to \"CC\""), this, SLOT(addCc())); - action->setEnabled(selectedCount); - action = contextMnu.addAction(QIcon(), tr("Add to \"BCC\""), this, SLOT(addBcc())); - action->setEnabled(selectedCount); - action = contextMnu.addAction(QIcon(), tr("Add as Recommend"), this, SLOT(addRecommend())); - action->setEnabled(selectedCount); - - contextMnu.addSeparator(); - - action = contextMnu.addAction(QIcon(IMAGE_FRIENDINFO), tr("Friend Details"), this, SLOT(friendDetails())); - action->setEnabled(selectedCount == 1 && idType == FriendSelectionWidget::IDTYPE_SSL); - - action = contextMnu.addAction(QIcon(), tr("Person Details"), this, SLOT(identityDetails())); - action->setEnabled(selectedCount == 1 && idType == FriendSelectionWidget::IDTYPE_GXS); - - contextMnu.exec(QCursor::pos()); -} - void MessageComposer::pasteRecommended() { QList links; @@ -2009,6 +1981,31 @@ void MessageComposer::setupFormatActions() } +void MessageComposer::setupContactActions() +{ + mActionAddTo = new QAction(tr("Add to \"To\""), this); + connect(mActionAddTo, SIGNAL(triggered(bool)), this, SLOT(addTo())); + mActionAddCC = new QAction(tr("Add to \"CC\""), this); + connect(mActionAddCC, SIGNAL(triggered(bool)), this, SLOT(addCc())); + mActionAddBCC = new QAction(tr("Add to \"BCC\""), this); + connect(mActionAddBCC, SIGNAL(triggered(bool)), this, SLOT(addBcc())); + mActionAddRecommend = new QAction(tr("Add as Recommend"), this); + connect(mActionAddRecommend, SIGNAL(triggered(bool)), this, SLOT(addRecommend())); + mActionContactDetails = new QAction(QIcon(IMAGE_FRIENDINFO), tr("Details"), this); + connect(mActionContactDetails, SIGNAL(triggered(bool)), this, SLOT(contactDetails())); + + ui.friendSelectionWidget->addContextMenuAction(mActionAddTo); + ui.friendSelectionWidget->addContextMenuAction(mActionAddCC); + ui.friendSelectionWidget->addContextMenuAction(mActionAddBCC); + ui.friendSelectionWidget->addContextMenuAction(mActionAddRecommend); + + QAction *action = new QAction(this); + action->setSeparator(true); + ui.friendSelectionWidget->addContextMenuAction(action); + + ui.friendSelectionWidget->addContextMenuAction(mActionContactDetails); +} + void MessageComposer::textBold() { QTextCharFormat fmt; @@ -2577,6 +2574,27 @@ void MessageComposer::filterComboBoxChanged(int i) } +void MessageComposer::friendSelectionChanged() +{ + std::set peerIds; + ui.friendSelectionWidget->selectedIds(peerIds, false); + + std::set gxsIds; + ui.friendSelectionWidget->selectedIds(gxsIds, false); + + int selectedCount = peerIds.size() + gxsIds.size(); + + mActionAddTo->setEnabled(selectedCount); + mActionAddCC->setEnabled(selectedCount); + mActionAddBCC->setEnabled(selectedCount); + mActionAddRecommend->setEnabled(selectedCount); + + FriendSelectionWidget::IdType idType; + ui.friendSelectionWidget->selectedId(idType); + + mActionContactDetails->setEnabled(selectedCount == 1 && (idType == FriendSelectionWidget::IDTYPE_SSL || idType == FriendSelectionWidget::IDTYPE_GXS)); +} + void MessageComposer::addTo() { addContact(TO); @@ -2613,35 +2631,37 @@ void MessageComposer::addRecommend() ui.msgText->setFocus(Qt::OtherFocusReason); } -void MessageComposer::friendDetails() +void MessageComposer::contactDetails() { FriendSelectionWidget::IdType idType; std::string id = ui.friendSelectionWidget->selectedId(idType); - if (id.empty() || idType != FriendSelectionWidget::IDTYPE_SSL) { + if (id.empty()) { return; } - ConfCertDialog::showIt(RsPeerId(id), ConfCertDialog::PageDetails); -} + switch (idType) { + case FriendSelectionWidget::IDTYPE_NONE: + case FriendSelectionWidget::IDTYPE_GROUP: + case FriendSelectionWidget::IDTYPE_GPG: + break; + case FriendSelectionWidget::IDTYPE_SSL: + ConfCertDialog::showIt(RsPeerId(id), ConfCertDialog::PageDetails); + break; + case FriendSelectionWidget::IDTYPE_GXS: + { + if (RsGxsGroupId(id).isNull()) { + return; + } -void MessageComposer::identityDetails() -{ - FriendSelectionWidget::IdType idType; - std::string id = ui.friendSelectionWidget->selectedId(idType); + IdDetailsDialog *dialog = new IdDetailsDialog(RsGxsGroupId(id)); + dialog->show(); - if (id.empty() || idType != FriendSelectionWidget::IDTYPE_GXS) { - return; + /* Dialog will destroy itself */ + } + break; } - if (RsGxsGroupId(id).isNull()) { - return; - } - - IdDetailsDialog *dialog = new IdDetailsDialog(RsGxsGroupId(id)); - dialog->show(); - - /* Dialog will destroy itself */ } void MessageComposer::tagAboutToShow() diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.h b/retroshare-gui/src/gui/msgs/MessageComposer.h index 6f2811730..ad286d858 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.h +++ b/retroshare-gui/src/gui/msgs/MessageComposer.h @@ -97,7 +97,6 @@ protected: private slots: /* toggle Contacts DockWidget */ void contextMenuFileList(QPoint); - void contextMenuMsgSendList(QPoint); void pasteRecommended(); void on_contactsdockWidget_visibilityChanged(bool visible); void toggleContacts(); @@ -153,10 +152,10 @@ private slots: void addBcc(); void addRecommend(); void editingRecipientFinished(); - void friendDetails(); - void identityDetails(); + void contactDetails(); void peerStatusChanged(const QString& peer_id, int status); + void friendSelectionChanged(); void tagAboutToShow(); void tagSet(int tagId, bool set); @@ -179,6 +178,7 @@ private: void setupViewActions(); void setupInsertActions(); void setupFormatActions(); + void setupContactActions(); bool load(const QString &f); bool maybeSave(); @@ -222,6 +222,11 @@ private: *actionUpperRoman; QAction *contactSidebarAction; + QAction *mActionAddTo; + QAction *mActionAddCC; + QAction *mActionAddBCC; + QAction *mActionAddRecommend; + QAction *mActionContactDetails; QTreeView *channelstreeView;