diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index e2eaa43f0..06410e18b 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -21,17 +21,18 @@ * */ +#include + #include "IdDialog.h" #include "gui/gxs/GxsIdTreeWidgetItem.h" +#include "gui/common/UIStateHelper.h" +#include #include #include #include "retroshare/rsgxsflags.h" #include -#include - -#include /****** * #define ID_DEBUG 1 @@ -45,7 +46,6 @@ /**************************************************************** */ - #define RSID_COL_NICKNAME 0 #define RSID_COL_KEYID 1 #define RSID_COL_IDTYPE 2 @@ -55,10 +55,11 @@ #define RSIDREP_COL_COMMENT 2 #define RSIDREP_COL_REPUTATION 3 -#define RSID_REQ_IDLIST 1 -#define RSID_REQ_IDDETAILS 2 -#define RSID_REQ_IDLISTDATA 3 -#define RSID_REQ_IDEDIT 4 +#define RSID_FILTER_YOURSELF 0x0001 +#define RSID_FILTER_FRIENDS 0x0002 +#define RSID_FILTER_OTHERS 0x0004 +#define RSID_FILTER_PSEUDONYMS 0x0008 +#define RSID_FILTER_ALL 0xffff /** Constructor */ IdDialog::IdDialog(QWidget *parent) @@ -66,75 +67,309 @@ IdDialog::IdDialog(QWidget *parent) { ui.setupUi(this); - mEditDialog = NULL; - //mPulseSelected = NULL; + mIdQueue = NULL; - ui.radioButton_ListAll->setChecked(true); - connect( ui.pushButton_NewId, SIGNAL(clicked()), this, SLOT(OpenOrShowAddDialog())); - connect( ui.pushButton_EditId, SIGNAL(clicked()), this, SLOT(OpenOrShowEditDialog())); + /* Setup UI helper */ + mStateHelper = new UIStateHelper(this); + mStateHelper->addWidget(IDDIALOG_IDLIST, ui.treeWidget_IdList); + mStateHelper->addLoadPlaceholder(IDDIALOG_IDLIST, ui.treeWidget_IdList, false); + mStateHelper->addClear(IDDIALOG_IDLIST, ui.treeWidget_IdList); + + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.lineEdit_Nickname); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.lineEdit_KeyId); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.lineEdit_GpgHash); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.lineEdit_GpgId); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.lineEdit_GpgName); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.pushButton_Reputation); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.pushButton_Delete); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.pushButton_EditId); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.line_RatingOverall); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.line_RatingImplicit); + mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui.line_RatingOwn); + + mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui.lineEdit_Nickname); + mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui.lineEdit_GpgName); + mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui.lineEdit_KeyId); + mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui.lineEdit_GpgHash); + mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui.lineEdit_GpgId); + mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui.lineEdit_GpgName); + mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui.line_RatingOverall); + mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui.line_RatingImplicit); + mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui.line_RatingOwn); + + mStateHelper->addClear(IDDIALOG_IDDETAILS, ui.lineEdit_Nickname); + mStateHelper->addClear(IDDIALOG_IDDETAILS, ui.lineEdit_GpgName); + mStateHelper->addClear(IDDIALOG_IDDETAILS, ui.lineEdit_KeyId); + mStateHelper->addClear(IDDIALOG_IDDETAILS, ui.lineEdit_GpgHash); + mStateHelper->addClear(IDDIALOG_IDDETAILS, ui.lineEdit_GpgId); + mStateHelper->addClear(IDDIALOG_IDDETAILS, ui.lineEdit_GpgName); + mStateHelper->addClear(IDDIALOG_IDDETAILS, ui.line_RatingOverall); + mStateHelper->addClear(IDDIALOG_IDDETAILS, ui.line_RatingImplicit); + mStateHelper->addClear(IDDIALOG_IDDETAILS, ui.line_RatingOwn); + + mStateHelper->addWidget(IDDIALOG_REPLIST, ui.treeWidget_RepList); + mStateHelper->addLoadPlaceholder(IDDIALOG_REPLIST, ui.treeWidget_RepList); + mStateHelper->addClear(IDDIALOG_REPLIST, ui.treeWidget_RepList); + + /* Connect signals */ + connect(ui.pushButton_NewId, SIGNAL(clicked()), this, SLOT(addIdentity())); + connect(ui.todoPushButton, SIGNAL(clicked()), this, SLOT(todo())); + connect(ui.pushButton_EditId, SIGNAL(clicked()), this, SLOT(editIdentity())); connect( ui.treeWidget_IdList, SIGNAL(itemSelectionChanged()), this, SLOT(updateSelection())); - connect( ui.radioButton_ListYourself, SIGNAL(toggled( bool ) ), this, SLOT(ListTypeToggled( bool ) ) ); - connect( ui.radioButton_ListFriends, SIGNAL(toggled( bool ) ), this, SLOT(ListTypeToggled( bool ) ) ); - connect( ui.radioButton_ListOthers, SIGNAL(toggled( bool ) ), this, SLOT(ListTypeToggled( bool ) ) ); - connect( ui.radioButton_ListPseudo, SIGNAL(toggled( bool ) ), this, SLOT(ListTypeToggled( bool ) ) ); - connect( ui.radioButton_ListAll, SIGNAL(toggled( bool ) ), this, SLOT(ListTypeToggled( bool ) ) ); + connect(ui.filterComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterComboBoxChanged())); + connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString))); + + /* Add filter types */ + ui.filterComboBox->addItem(tr("All"), RSID_FILTER_ALL); + ui.filterComboBox->addItem(tr("Yourself"), RSID_FILTER_YOURSELF); + ui.filterComboBox->addItem(tr("Friends / Friends of Friends"), RSID_FILTER_FRIENDS); + ui.filterComboBox->addItem(tr("Others"), RSID_FILTER_OTHERS); + ui.filterComboBox->addItem(tr("Pseudonyms"), RSID_FILTER_PSEUDONYMS); + ui.filterComboBox->setCurrentIndex(0); + + /* Add filter actions */ + QTreeWidgetItem *headerItem = ui.treeWidget_IdList->headerItem(); + QString headerText = headerItem->text(RSID_COL_NICKNAME); + ui.filterLineEdit->addFilter(QIcon(), headerText, RSID_COL_NICKNAME, QString("%1 %2").arg(tr("Search"), headerText)); + headerText = headerItem->text(RSID_COL_KEYID); + ui.filterLineEdit->addFilter(QIcon(), headerItem->text(RSID_COL_KEYID), RSID_COL_KEYID, QString("%1 %2").arg(tr("Search"), headerText)); + + /* Setup tree */ + ui.treeWidget_IdList->sortByColumn(RSID_COL_NICKNAME, Qt::AscendingOrder); QTimer *timer = new RsProtectedTimer(this); timer->connect(timer, SIGNAL(timeout()), this, SLOT(checkUpdate())); timer->start(1000); mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this); + + mStateHelper->setActive(IDDIALOG_IDDETAILS, false); + mStateHelper->setActive(IDDIALOG_REPLIST, false); } -void IdDialog::ListTypeToggled(bool checked) +void IdDialog::todo() { - if (checked) + QMessageBox::information(this, "Todo", + "Open points:
    " + "
  • Initial fill of data" + "
  • Delete ID" + "
  • Edit ID" + "
  • Reputation" + "
  • Load/save settings" + "
"); +} + +void IdDialog::filterComboBoxChanged() { requestIdList(); } + +void IdDialog::filterChanged(const QString& /*text*/) +{ + filterIds(); } - - void IdDialog::updateSelection() { - /* */ QTreeWidgetItem *item = ui.treeWidget_IdList->currentItem(); + std::string id; - if (!item) + if (item) { - blankSelection(); + id = item->text(RSID_COL_KEYID).toStdString(); + } + + requestIdDetails(id); +} + +void IdDialog::requestIdList() +{ + if (!mIdQueue) + return; + + mStateHelper->setLoading(IDDIALOG_IDLIST, true); + mStateHelper->setLoading(IDDIALOG_IDDETAILS, true); + mStateHelper->setLoading(IDDIALOG_REPLIST, true); + + mIdQueue->cancelActiveRequestTokens(IDDIALOG_IDLIST); + + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; + + uint32_t token; + + mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, IDDIALOG_IDLIST); +} + +bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, const std::string &ownPgpId, int accept) +{ + bool isOwnId = (data.mPgpKnown && (data.mPgpId == ownPgpId)) || (data.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN); + + /* do filtering */ + bool ok = false; + if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) + { + if (isOwnId && (accept & RSID_FILTER_YOURSELF)) + { + ok = true; + } + else + { + if (data.mPgpKnown) + { + if (accept & RSID_FILTER_FRIENDS) + { + ok = true; + } + } + else + { + if (accept & RSID_FILTER_OTHERS) + { + ok = true; + } + } + } } else { - std::string id = item->text(RSID_COL_KEYID).toStdString(); - requestIdDetails(id); + if (accept & RSID_FILTER_PSEUDONYMS) + { + ok = true; + } + + if (isOwnId && (accept & RSID_FILTER_YOURSELF)) + { + ok = true; + } + } + + if (!ok) + { + return false; + } + + if (!item) + { + item = new QTreeWidgetItem(); + } + item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str())); + item->setText(RSID_COL_KEYID, QString::fromStdString(data.mMeta.mGroupId)); + + if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) + { + if (data.mPgpKnown) + { + RsPeerDetails details; + rsPeers->getGPGDetails(data.mPgpId, details); + item->setText(RSID_COL_IDTYPE, QString::fromUtf8(details.name.c_str())); + } + else + { + item->setText(RSID_COL_IDTYPE, tr("PGP Linked Id")); } } + else + { + item->setText(RSID_COL_IDTYPE, tr("Anon Id")); + } - -void IdDialog::blankSelection() -{ - /* blank it all - and fix buttons */ - ui.lineEdit_Nickname->setText(""); - ui.lineEdit_KeyId->setText(""); - ui.lineEdit_GpgHash->setText(""); - ui.lineEdit_GpgId->setText(""); - ui.lineEdit_GpgName->setText(""); - ui.lineEdit_GpgEmail->setText(""); - - ui.pushButton_Reputation->setEnabled(false); - ui.pushButton_Delete->setEnabled(false); - ui.pushButton_EditId->setEnabled(false); - ui.pushButton_NewId->setEnabled(true); + return true; } +void IdDialog::insertIdList(uint32_t token) +{ + mStateHelper->setLoading(IDDIALOG_IDLIST, false); + int accept = ui.filterComboBox->itemData(ui.filterComboBox->currentIndex()).toInt(); + RsGxsIdGroup data; + std::vector datavector; + std::vector::iterator vit; + if (!rsIdentity->getGroupData(token, datavector)) + { + std::cerr << "IdDialog::insertIdList() Error getting GroupData"; + std::cerr << std::endl; + + mStateHelper->setLoading(IDDIALOG_IDDETAILS, false); + mStateHelper->setLoading(IDDIALOG_REPLIST, false); + mStateHelper->setActive(IDDIALOG_IDLIST, false); + mStateHelper->setActive(IDDIALOG_IDDETAILS, false); + mStateHelper->setActive(IDDIALOG_REPLIST, false); + mStateHelper->clear(IDDIALOG_IDLIST); + mStateHelper->clear(IDDIALOG_IDDETAILS); + mStateHelper->clear(IDDIALOG_REPLIST); + + return; +} + + mStateHelper->setActive(IDDIALOG_IDLIST, true); + + std::string ownPgpId = rsPeers->getGPGOwnId(); + + /* Update existing and remove not existing items */ + QTreeWidgetItemIterator itemIterator(ui.treeWidget_IdList); + QTreeWidgetItem *item = NULL; + while ((item = *itemIterator) != NULL) { + itemIterator++; + + for (vit = datavector.begin(); vit != datavector.end(); ++vit) + { + if (vit->mMeta.mGroupId == item->text(RSID_COL_KEYID).toStdString()) + { + break; + } + } + if (vit == datavector.end()) + { + delete(item); + } else { + if (!fillIdListItem(*vit, item, ownPgpId, accept)) + { + delete(item); + } + datavector.erase(vit); + } + } + + /* Insert new items */ + for (vit = datavector.begin(); vit != datavector.end(); ++vit) + { + data = (*vit); + + item = NULL; + if (fillIdListItem(*vit, item, ownPgpId, accept)) + { + ui.treeWidget_IdList->addTopLevelItem(item); + } + } + + filterIds(); + + // fix up buttons. + updateSelection(); +} void IdDialog::requestIdDetails(std::string &id) { + mIdQueue->cancelActiveRequestTokens(IDDIALOG_IDDETAILS); + + if (id.empty()) + { + mStateHelper->setActive(IDDIALOG_IDDETAILS, false); + mStateHelper->setActive(IDDIALOG_REPLIST, false); + mStateHelper->setLoading(IDDIALOG_IDDETAILS, false); + mStateHelper->setLoading(IDDIALOG_REPLIST, false); + mStateHelper->clear(IDDIALOG_IDDETAILS); + mStateHelper->clear(IDDIALOG_REPLIST); + + return; + } + + mStateHelper->setLoading(IDDIALOG_IDDETAILS, true); + mStateHelper->setLoading(IDDIALOG_REPLIST, true); + RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; @@ -145,25 +380,43 @@ void IdDialog::requestIdDetails(std::string &id) mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDDIALOG_IDDETAILS); } - void IdDialog::insertIdDetails(uint32_t token) { + mStateHelper->setLoading(IDDIALOG_IDDETAILS, false); + /* get details from libretroshare */ RsGxsIdGroup data; std::vector datavector; if (!rsIdentity->getGroupData(token, datavector)) { + mStateHelper->setActive(IDDIALOG_IDDETAILS, false); + mStateHelper->setActive(IDDIALOG_REPLIST, false); + mStateHelper->setLoading(IDDIALOG_REPLIST, false); + mStateHelper->clear(IDDIALOG_IDDETAILS); + mStateHelper->clear(IDDIALOG_REPLIST); + ui.lineEdit_KeyId->setText("ERROR GETTING KEY!"); + return; } if (datavector.size() != 1) { std::cerr << "IdDialog::insertIdDetails() Invalid datavector size"; + + mStateHelper->setActive(IDDIALOG_IDDETAILS, false); + mStateHelper->setActive(IDDIALOG_REPLIST, false); + mStateHelper->setLoading(IDDIALOG_REPLIST, false); + mStateHelper->clear(IDDIALOG_IDDETAILS); + mStateHelper->clear(IDDIALOG_REPLIST); + ui.lineEdit_KeyId->setText("INVALID DV SIZE"); + return; } + mStateHelper->setActive(IDDIALOG_IDDETAILS, true); + data = datavector[0]; /* get GPG Details from rsPeers */ @@ -179,24 +432,20 @@ void IdDialog::insertIdDetails(uint32_t token) RsPeerDetails details; rsPeers->getGPGDetails(data.mPgpId, details); ui.lineEdit_GpgName->setText(QString::fromStdString(details.name)); - ui.lineEdit_GpgEmail->setText(QString::fromStdString(details.email)); } else { if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) { - ui.lineEdit_GpgName->setText("Unknown Real Name"); - ui.lineEdit_GpgEmail->setText("Unknown Email"); + ui.lineEdit_GpgName->setText(tr("Unknown real name")); } else { - ui.lineEdit_GpgName->setText("Anonymous Id"); - ui.lineEdit_GpgEmail->setText("-- N/A --"); + ui.lineEdit_GpgName->setText(tr("Anonymous Id")); } } - bool isOwnId = (data.mPgpKnown && (data.mPgpId == ownPgpId)) || - (data.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN); + bool isOwnId = (data.mPgpKnown && (data.mPgpId == ownPgpId)) || (data.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN); if (isOwnId) { @@ -225,23 +474,22 @@ void IdDialog::insertIdDetails(uint32_t token) ui.radioButton_IdPseudo->setChecked(true); } - ui.pushButton_NewId->setEnabled(true); - if (isOwnId) { - ui.pushButton_Reputation->setEnabled(false); - ui.pushButton_Delete->setEnabled(true); + mStateHelper->setWidgetEnabled(ui.pushButton_Reputation, false); + // No Delete Ids yet! + mStateHelper->setWidgetEnabled(ui.pushButton_Delete, /*true*/ false); // No Editing Ids yet! - //ui.pushButton_EditId->setEnabled(true); + mStateHelper->setWidgetEnabled(ui.pushButton_EditId, /*true*/ false); } else { - ui.pushButton_Reputation->setEnabled(true); - ui.pushButton_Delete->setEnabled(false); - ui.pushButton_EditId->setEnabled(false); + // No Reputation yet! + mStateHelper->setWidgetEnabled(ui.pushButton_Reputation, /*true*/ false); + mStateHelper->setWidgetEnabled(ui.pushButton_Delete, false); + mStateHelper->setWidgetEnabled(ui.pushButton_EditId, false); } - /* now fill in the reputation information */ ui.line_RatingOverall->setText("Overall Rating TODO"); ui.line_RatingOwn->setText("Own Rating TODO"); @@ -261,7 +509,6 @@ void IdDialog::insertIdDetails(uint32_t token) /* request network ratings */ requestRepList(data.mMeta.mGroupId); - } void IdDialog::checkUpdate() @@ -274,175 +521,46 @@ void IdDialog::checkUpdate() { requestIdList(); } - return; } - -void IdDialog::OpenOrShowAddDialog() +void IdDialog::addIdentity() { - if (!mEditDialog) - { - mEditDialog = new IdEditDialog(NULL); - } - bool pseudo = false; - mEditDialog->setupNewId(pseudo); - - mEditDialog->show(); - -} - - -void IdDialog::OpenOrShowEditDialog() -{ - if (!mEditDialog) - { - mEditDialog = new IdEditDialog(NULL); + IdEditDialog dlg(this); + dlg.setupNewId(false); + dlg.exec(); } - - /* */ +void IdDialog::editIdentity() +{ QTreeWidgetItem *item = ui.treeWidget_IdList->currentItem(); - if (!item) { - std::cerr << "IdDialog::OpenOrShowEditDialog() Invalid item"; + std::cerr << "IdDialog::editIdentity() Invalid item"; std::cerr << std::endl; return; } std::string keyId = item->text(RSID_COL_KEYID).toStdString(); - if (mEditDialog) - { - mEditDialog->setupExistingId(keyId); - mEditDialog->show(); + IdEditDialog dlg(this); + dlg.setupExistingId(keyId); + dlg.exec(); } -} -void IdDialog::requestIdList() +void IdDialog::filterIds() { - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; + int filterColumn = ui.filterLineEdit->currentFilter(); + QString text = ui.filterLineEdit->text(); - uint32_t token; - std::list groupIds; - - mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, IDDIALOG_IDLIST); + ui.treeWidget_IdList->filterItems(filterColumn, text); } -void IdDialog::insertIdList(uint32_t token) -{ - QTreeWidget *tree = ui.treeWidget_IdList; - - tree->clear(); - - std::list ids; - std::list::iterator it; - - bool acceptAll = ui.radioButton_ListAll->isChecked(); - bool acceptPseudo = ui.radioButton_ListPseudo->isChecked(); - bool acceptYourself = ui.radioButton_ListYourself->isChecked(); - bool acceptFriends = ui.radioButton_ListFriends->isChecked(); - bool acceptOthers = ui.radioButton_ListOthers->isChecked(); - - RsGxsIdGroup data; - std::vector datavector; - std::vector::iterator vit; - if (!rsIdentity->getGroupData(token, datavector)) - { - std::cerr << "IdDialog::insertIdList() Error getting GroupData"; - std::cerr << std::endl; - return; - } - - std::string ownPgpId = rsPeers->getGPGOwnId(); - - for(vit = datavector.begin(); vit != datavector.end(); vit++) - { - data = (*vit); - - bool isOwnId = (data.mPgpKnown && (data.mPgpId == ownPgpId)) || - (data.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN); - - /* do filtering */ - bool ok = false; - if (acceptAll) - { - ok = true; - } - else if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) - { - if (isOwnId && acceptYourself) - { - ok = true; - } - else - { - if (data.mPgpKnown) - { - if (acceptFriends) - { - ok = true; - } - } - else - { - if (acceptOthers) - { - ok = true; - } - } - } - } - else - { - if (acceptPseudo) - { - ok = true; - } - - if (isOwnId && acceptYourself) - { - ok = true; - } - } - - if (!ok) - { - continue; - } - - QTreeWidgetItem *item = new QTreeWidgetItem(); - item->setText(RSID_COL_NICKNAME, QString::fromStdString(data.mMeta.mGroupName)); - item->setText(RSID_COL_KEYID, QString::fromStdString(data.mMeta.mGroupId)); - if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) - { - if (data.mPgpKnown) - { - RsPeerDetails details; - rsPeers->getGPGDetails(data.mPgpId, details); - item->setText(RSID_COL_IDTYPE, QString::fromStdString(details.name)); - } - else - { - item->setText(RSID_COL_IDTYPE, "PGP Linked Id"); - } - } - else - { - item->setText(RSID_COL_IDTYPE, "Anon Id"); - } - - tree->addTopLevelItem(item); - } - - // fix up buttons. - updateSelection(); -} - - void IdDialog::requestRepList(const RsGxsGroupId &aboutId) { + mStateHelper->setLoading(IDDIALOG_REPLIST, true); + + mIdQueue->cancelActiveRequestTokens(IDDIALOG_REPLIST); + std::list groupIds; groupIds.push_back(aboutId); @@ -451,18 +569,11 @@ void IdDialog::requestRepList(const RsGxsGroupId &aboutId) uint32_t token; mIdQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDDIALOG_REPLIST); - } - void IdDialog::insertRepList(uint32_t token) { - QTreeWidget *tree = ui.treeWidget_RepList; - - tree->clear(); - - std::list ids; - std::list::iterator it; + mStateHelper->setLoading(IDDIALOG_REPLIST, false); std::vector opinions; std::vector::iterator vit; @@ -470,9 +581,15 @@ void IdDialog::insertRepList(uint32_t token) { std::cerr << "IdDialog::insertRepList() Error getting Opinions"; std::cerr << std::endl; + + mStateHelper->setActive(IDDIALOG_REPLIST, false); + mStateHelper->clear(IDDIALOG_REPLIST); + return; } + mStateHelper->setActive(IDDIALOG_REPLIST, true); + for(vit = opinions.begin(); vit != opinions.end(); vit++) { RsGxsIdOpinion &op = (*vit); @@ -492,15 +609,11 @@ void IdDialog::insertRepList(uint32_t token) /* local reputation */ item->setText(RSIDREP_COL_REPUTATION, QString::number(op.getReputation())); - - tree->addTopLevelItem(item); + ui.treeWidget_RepList->addTopLevelItem(item); } - - // fix up buttons. - updateSelection(); } -void IdDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) +void IdDialog::loadRequest(const TokenQueue */*queue*/, const TokenRequest &req) { std::cerr << "IdDialog::loadRequest() UserType: " << req.mUserType; std::cerr << std::endl; @@ -523,10 +636,5 @@ void IdDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) std::cerr << "IdDialog::loadRequest() ERROR"; std::cerr << std::endl; break; - } } - - - - diff --git a/retroshare-gui/src/gui/Identity/IdDialog.h b/retroshare-gui/src/gui/Identity/IdDialog.h index 815949134..4748d7b1f 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDialog.h @@ -21,8 +21,8 @@ * */ -#ifndef MRK_IDENTITY_DIALOG_H -#define MRK_IDENTITY_DIALOG_H +#ifndef IDENTITYDIALOG_H +#define IDENTITYDIALOG_H #include "retroshare-gui/mainpage.h" #include "ui_IdDialog.h" @@ -34,34 +34,38 @@ #include "gui/Identity/IdEditDialog.h" #include "util/TokenQueue.h" +class UIStateHelper; + class IdDialog : public MainPage, public TokenResponse { - Q_OBJECT + Q_OBJECT public: IdDialog(QWidget *parent = 0); -void loadRequest(const TokenQueue *queue, const TokenRequest &req); + void loadRequest(const TokenQueue *queue, const TokenRequest &req); private slots: + void filterComboBoxChanged(); + void filterChanged(const QString &text); - - void ListTypeToggled(bool checked); void checkUpdate(); - void OpenOrShowAddDialog(); - void OpenOrShowEditDialog(); + void addIdentity(); + void editIdentity(); void updateSelection(); -private: + void todo(); - void blankSelection(); +private: void requestIdDetails(std::string &id); void insertIdDetails(uint32_t token); void requestIdList(); void requestIdData(std::list &ids); + bool fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, const std::string &ownPgpId, int accept); void insertIdList(uint32_t token); + void filterIds(); void requestRepList(const RsGxsGroupId &aboutId); void insertRepList(uint32_t token); @@ -69,14 +73,12 @@ private: void requestIdEdit(std::string &id); void showIdEdit(uint32_t token); - IdEditDialog *mEditDialog; - +private: TokenQueue *mIdQueue; + UIStateHelper *mStateHelper; /* UI - from Designer */ Ui::IdDialog ui; - }; #endif - diff --git a/retroshare-gui/src/gui/Identity/IdDialog.ui b/retroshare-gui/src/gui/Identity/IdDialog.ui index ea808768d..6767b49b0 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.ui +++ b/retroshare-gui/src/gui/Identity/IdDialog.ui @@ -15,40 +15,48 @@ - + 6 - - 0 - - - + + - QFrame::StyledPanel + QFrame::Box - QFrame::Raised + QFrame::Sunken - 1 + 2 - + + + + 24 + 24 + + :/images/groupchat.png + + false + - + - 11 + 10 + 75 + true @@ -57,7 +65,7 @@ - + Qt::Horizontal @@ -76,79 +84,38 @@ + + + + Todo + + + - - - - Showing: + + + + + + Show: + + + + + + + + + + + + + + + true - - - - - Yourself - - - - - - - Friends / Friends of Friends - - - - - - - Others - - - - - - - Qt::Horizontal - - - - - - - Pseudonyms - - - - - - - Qt::Horizontal - - - - - - - All - - - - - - - - - - filter - - - - - - - - Nickname @@ -169,12 +136,18 @@ - + - + + + QFrame::Box + + + QFrame::Sunken + - 3 + 2 @@ -183,13 +156,6 @@ - - - - Edit Reputation - - - @@ -198,7 +164,14 @@ - + + + Edit Reputation + + + + + Qt::Horizontal @@ -214,7 +187,7 @@ - + Identity Type @@ -346,23 +319,6 @@ - - - - PGP Email - - - - - - - true - - - true - - - @@ -401,14 +357,24 @@ - + Reputation - - - - + + + + + + + Implicit Score + + + + + + + @@ -421,37 +387,23 @@ - - - - Implicit Score - - + + - + Your Rating - - - - - - - - - - - + - - + + Friend @@ -481,6 +433,42 @@ + + + LineEditClear + QLineEdit +
gui/common/LineEditClear.h
+
+ + RSTreeWidget + QTreeWidget +
gui/common/RSTreeWidget.h
+
+
+ + pushButton_NewId + todoPushButton + filterComboBox + filterLineEdit + treeWidget_IdList + pushButton_Delete + pushButton_EditId + pushButton_Reputation + lineEdit_Nickname + lineEdit_KeyId + lineEdit_GpgHash + lineEdit_GpgId + lineEdit_GpgName + radioButton_IdYourself + radioButton_IdFriend + radioButton_IdFOF + radioButton_IdOther + radioButton_IdPseudo + line_RatingOverall + line_RatingImplicit + line_RatingOwn + treeWidget_RepList + diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp index 3bad7dead..c98972806 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -22,6 +22,7 @@ */ #include "gui/Identity/IdEditDialog.h" +#include "gui/common/UIStateHelper.h" #include "util/TokenQueue.h" #include @@ -33,22 +34,46 @@ /** Constructor */ IdEditDialog::IdEditDialog(QWidget *parent) -: QWidget(parent) +: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint) { + mIsNew = true; + ui.setupUi(this); - connect(ui.radioButton_GpgId, SIGNAL( toggled( bool ) ), this, SLOT( IdTypeToggled( bool ) ) ); - connect(ui.radioButton_Pseudo, SIGNAL( toggled( bool ) ), this, SLOT( IdTypeToggled( bool ) ) ); - connect(ui.pushButton_Update, SIGNAL( clicked( void ) ), this, SLOT( updateId( void ) ) ); - connect(ui.pushButton_Cancel, SIGNAL( clicked( void ) ), this, SLOT( cancelId( void ) ) ); + /* Setup UI helper */ + mStateHelper = new UIStateHelper(this); + + mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_Nickname); + mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_KeyId); + mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_GpgHash); + mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_GpgId); + mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_GpgName); + mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.radioButton_GpgId); + mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.radioButton_Pseudo); + + mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_Nickname); + mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_GpgName); + mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_KeyId); + mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_GpgHash); + mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_GpgId); + mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_GpgName); + + /* Connect signals */ + connect(ui.radioButton_GpgId, SIGNAL(toggled(bool)), this, SLOT(idTypeToggled(bool))); + connect(ui.radioButton_Pseudo, SIGNAL(toggled(bool)), this, SLOT(idTypeToggled(bool))); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(updateId())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close())); + mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this); } void IdEditDialog::setupNewId(bool pseudo) { - ui.checkBox_NewId->setChecked(true); - ui.checkBox_NewId->setEnabled(false); - ui.lineEdit_KeyId->setText("To Be Generated"); + setWindowTitle(tr("New identity")); + + mIsNew = true; + + ui.lineEdit_KeyId->setText(tr("To be generated")); ui.lineEdit_Nickname->setText(""); ui.radioButton_GpgId->setEnabled(true); ui.radioButton_Pseudo->setEnabled(true); @@ -63,11 +88,10 @@ void IdEditDialog::setupNewId(bool pseudo) } // force - incase it wasn't triggered. - IdTypeToggled(true); - return; + idTypeToggled(true); } -void IdEditDialog::IdTypeToggled(bool checked) +void IdEditDialog::idTypeToggled(bool checked) { if (checked) { @@ -80,10 +104,9 @@ void IdEditDialog::updateIdType(bool pseudo) { if (pseudo) { - ui.lineEdit_GpgHash->setText("N/A"); - ui.lineEdit_GpgId->setText("N/A"); - ui.lineEdit_GpgName->setText("N/A"); - ui.lineEdit_GpgEmail->setText("N/A"); + ui.lineEdit_GpgHash->setText(tr("N/A")); + ui.lineEdit_GpgId->setText(tr("N/A")); + ui.lineEdit_GpgName->setText(tr("N/A")); } else { @@ -93,39 +116,39 @@ void IdEditDialog::updateIdType(bool pseudo) rsPeers->getPeerDetails(gpgid, details); ui.lineEdit_GpgId->setText(QString::fromStdString(gpgid)); - ui.lineEdit_GpgHash->setText("To Be Generated"); + ui.lineEdit_GpgHash->setText(tr("To be generated")); ui.lineEdit_GpgName->setText(QString::fromStdString(details.name)); - ui.lineEdit_GpgEmail->setText(QString::fromStdString(details.email)); } - return; } - void IdEditDialog::setupExistingId(std::string keyId) { - RsTokReqOptions opts; + setWindowTitle(tr("Edit identity")); - std::list groupIds; - groupIds.push_back(keyId); + mIsNew = false; - uint32_t token; - mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDEDITDIALOG_LOADID); + mStateHelper->setLoading(IDEDITDIALOG_LOADID, true); + + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; + + std::list groupIds; + groupIds.push_back(keyId); + + uint32_t token; + mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDEDITDIALOG_LOADID); } - void IdEditDialog::loadExistingId(uint32_t token) { - ui.checkBox_NewId->setChecked(false); - ui.checkBox_NewId->setEnabled(false); - ui.radioButton_GpgId->setEnabled(false); - ui.radioButton_Pseudo->setEnabled(false); + mStateHelper->setLoading(IDEDITDIALOG_LOADID, false); - /* get details from libretroshare */ + /* get details from libretroshare */ RsGxsIdGroup data; std::vector datavector; if (!rsIdentity->getGroupData(token, datavector)) { - ui.lineEdit_KeyId->setText("ERROR GETTING KEY!"); + ui.lineEdit_KeyId->setText(tr("Error getting key!")); return; } @@ -134,13 +157,12 @@ void IdEditDialog::loadExistingId(uint32_t token) std::cerr << "IdDialog::insertIdDetails() Invalid datavector size"; std::cerr << std::endl; - ui.lineEdit_KeyId->setText("ERROR KEYID INVALID"); + ui.lineEdit_KeyId->setText(tr("Error KeyID invalid")); ui.lineEdit_Nickname->setText(""); - ui.lineEdit_GpgHash->setText("N/A"); - ui.lineEdit_GpgId->setText("N/A"); - ui.lineEdit_GpgName->setText("N/A"); - ui.lineEdit_GpgEmail->setText("N/A"); + ui.lineEdit_GpgHash->setText(tr("N/A")); + ui.lineEdit_GpgId->setText(tr("N/A")); + ui.lineEdit_GpgName->setText(tr("N/A")); return; } @@ -159,10 +181,10 @@ void IdEditDialog::loadExistingId(uint32_t token) // DOES THIS TRIGGER ALREADY??? // force - incase it wasn't triggered. - IdTypeToggled(true); + idTypeToggled(true); ui.lineEdit_Nickname->setText(QString::fromStdString(data.mMeta.mGroupName)); - ui.lineEdit_KeyId->setText(QString::fromStdString(data.mMeta.mGroupId)); + ui.lineEdit_KeyId->setText(QString::fromStdString(data.mMeta.mGroupId)); if (realid) { @@ -173,26 +195,21 @@ void IdEditDialog::loadExistingId(uint32_t token) RsPeerDetails details; rsPeers->getGPGDetails(data.mPgpId, details); ui.lineEdit_GpgName->setText(QString::fromStdString(details.name)); - ui.lineEdit_GpgEmail->setText(QString::fromStdString(details.email)); ui.lineEdit_GpgId->setText(QString::fromStdString(data.mPgpId)); } else { - ui.lineEdit_GpgId->setText("Unknown PgpId"); - ui.lineEdit_GpgName->setText("Unknown Real Name"); - ui.lineEdit_GpgEmail->setText("Unknown Email"); + ui.lineEdit_GpgId->setText(tr("Unknown GpgId")); + ui.lineEdit_GpgName->setText(tr("Unknown real name")); } } else { - ui.lineEdit_GpgHash->setText("N/A"); - ui.lineEdit_GpgId->setText("N/A"); - ui.lineEdit_GpgName->setText("N/A"); - ui.lineEdit_GpgEmail->setText("N/A"); + ui.lineEdit_GpgHash->setText(tr("N/A")); + ui.lineEdit_GpgId->setText(tr("N/A")); + ui.lineEdit_GpgName->setText(tr("N/A")); } - - return; } void IdEditDialog::updateId() @@ -200,7 +217,6 @@ void IdEditDialog::updateId() RsGxsIdGroup rid; // Must set, Nickname, KeyId(if existing), mIdType, GpgId. - rid.mMeta.mGroupName = ui.lineEdit_Nickname->text().toStdString(); if (rid.mMeta.mGroupName.size() < 2) @@ -211,7 +227,7 @@ void IdEditDialog::updateId() } //rid.mIdType = RSID_RELATION_YOURSELF; - if (ui.checkBox_NewId->isChecked()) + if (mIsNew) { rid.mMeta.mGroupId = ""; } @@ -227,7 +243,6 @@ void IdEditDialog::updateId() //rid.mGpgId = ui.lineEdit_GpgId->text().toStdString(); rid.mPgpIdHash = ui.lineEdit_GpgHash->text().toStdString(); //rid.mGpgName = ui.lineEdit_GpgName->text().toStdString(); - //rid.mGpgEmail = ui.lineEdit_GpgEmail->text().toStdString(); } else { @@ -238,7 +253,6 @@ void IdEditDialog::updateId() //rid.mGpgName = ""; //rid.mGpgEmail = ""; } - // Can only create Identities for the moment! RsIdentityParameters params; @@ -248,23 +262,10 @@ void IdEditDialog::updateId() uint32_t dummyToken = 0; rsIdentity->createIdentity(dummyToken, params); - hide(); - return; + close(); } -void IdEditDialog::cancelId() -{ - hide(); - return; -} - -void IdEditDialog::clearDialog() -{ - return; -} - - -void IdEditDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) +void IdEditDialog::loadRequest(const TokenQueue */*queue*/, const TokenRequest &req) { std::cerr << "IdDialog::loadRequest() UserType: " << req.mUserType; std::cerr << std::endl; @@ -272,5 +273,3 @@ void IdEditDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) // only one here! loadExistingId(req.mToken); } - - diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.h b/retroshare-gui/src/gui/Identity/IdEditDialog.h index f6b29a5a4..8ef672710 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.h +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.h @@ -21,8 +21,8 @@ * */ -#ifndef MRK_ID_EDIT_DIALOG_H -#define MRK_ID_EDIT_DIALOG_H +#ifndef IDEDITDIALOG_H +#define IDEDITDIALOG_H #include "ui_IdEditDialog.h" @@ -30,35 +30,34 @@ #include "util/TokenQueue.h" -class IdEditDialog : public QWidget, public TokenResponse +class UIStateHelper; + +class IdEditDialog : public QDialog, public TokenResponse { - Q_OBJECT + Q_OBJECT public: IdEditDialog(QWidget *parent = 0); void setupNewId(bool pseudo); void setupExistingId(std::string keyId); - void loadExistingId(uint32_t token); -void loadRequest(const TokenQueue *queue, const TokenRequest &req); + void loadRequest(const TokenQueue *queue, const TokenRequest &req); private slots: - - void IdTypeToggled(bool checked); + void idTypeToggled(bool checked); void updateId(); - void cancelId(); private: void updateIdType(bool pseudo); - void clearDialog(); + void loadExistingId(uint32_t token); protected: - Ui::IdEditDialog ui; + bool mIsNew; + UIStateHelper *mStateHelper; TokenQueue *mIdQueue; }; #endif - diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.ui b/retroshare-gui/src/gui/Identity/IdEditDialog.ui index 6961d5c17..2a9dd713b 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.ui +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.ui @@ -1,18 +1,21 @@ IdEditDialog - + 0 0 557 - 229 + 179 + + QFormLayout::AllNonFixedFieldsGrow + @@ -31,7 +34,39 @@ - + + + true + + + + + + + PGP Hash + + + + + + + true + + + + + + + PGP Id + + + + + + + true + + @@ -41,19 +76,13 @@ - - - - - - PGP Email + + + true - - - Qt::Vertical @@ -66,50 +95,10 @@ - - - - - - - PGP Hash - - - - - - - - - - PGP Id - - - - - - - New Identity - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -126,43 +115,42 @@
+ + + + Qt::Vertical + + + + 20 + 40 + + + +
- - - - - Cancel - - - - - - - Qt::Horizontal - - - - 288 - 20 - - - - - - - - Create/Update ID - - - - + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + lineEdit_Nickname + lineEdit_KeyId + lineEdit_GpgHash + lineEdit_GpgId + lineEdit_GpgName + radioButton_GpgId + radioButton_Pseudo + buttonBox + diff --git a/retroshare-gui/src/gui/common/UIStateHelper.cpp b/retroshare-gui/src/gui/common/UIStateHelper.cpp new file mode 100644 index 000000000..bab3d388a --- /dev/null +++ b/retroshare-gui/src/gui/common/UIStateHelper.cpp @@ -0,0 +1,465 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2013 RetroShare Team + * + * This program 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include +#include +#include + +#include "UIStateHelper.h" +#include "RSTreeWidget.h" +#include "LinkTextBrowser.h" + +class UIStateHelperObject +{ +public: + UIStateHelperObject(QLabel *widget) + { + init(); + mLabel = widget; + } + UIStateHelperObject(QLineEdit *widget) + { + init(); + mLineEdit = widget; + } + UIStateHelperObject(RSTreeWidget *widget) + { + init(); + mTreeWidget = widget; + } + UIStateHelperObject(LinkTextBrowser *widget) + { + init(); + mLinkTextBrowser = widget; + } + + void setPlaceholder(bool loading, const QString &text, bool clear) const + { + if (mLabel) { + mLabel->setText(text); + } + + if (mLineEdit) { + if (loading && clear) { + mLineEdit->clear(); + } + +#if QT_VERSION >= QT_VERSION_CHECK (4, 8, 0) + mLineEdit->setPlaceholderText(text); +#else + mLineEdit->setText(text); +#endif + } + + if (mTreeWidget) { + if (loading && clear) { + mTreeWidget->clear(); + } + + mTreeWidget->setPlaceholderText(text); + } + + if (mLinkTextBrowser) { + if (loading && clear) { + mLinkTextBrowser->clear(); + } + + mLinkTextBrowser->setPlaceholderText(text); + } + } + + void clear() + { + if (mLabel) { + mLabel->clear(); + } + + if (mLineEdit) { + mLineEdit->clear(); + } + + if (mTreeWidget) { + mTreeWidget->clear(); + } + + if (mLinkTextBrowser) { + mLinkTextBrowser->clear(); + } + } + + bool operator ==(const UIStateHelperObject &data) const + { + if (mLabel == data.mLabel && + mLineEdit == data.mLineEdit && + mTreeWidget == data.mTreeWidget && + mLinkTextBrowser == data.mLinkTextBrowser) { + return true; + } + + return false; + } + + bool operator <(const UIStateHelperObject &data) const + { + if (mLabel < data.mLabel || + mLineEdit < data.mLineEdit || + mTreeWidget < data.mTreeWidget || + mLinkTextBrowser < data.mLinkTextBrowser) { + return true; + } + + return false; + } + +private: + void init() + { + mLabel = NULL; + mLineEdit = NULL; + mTreeWidget = NULL; + mLinkTextBrowser = NULL; + } + +private: + QLabel *mLabel; + QLineEdit *mLineEdit; + RSTreeWidget *mTreeWidget; + LinkTextBrowser *mLinkTextBrowser; +}; + +class UIStateHelperData +{ +public: + UIStateHelperData() + { + mLoading = false; + mActive = true; + } + +public: + bool mLoading; + bool mActive; + QMap mWidgets; + QMap > mLoad; + QList mClear; +}; + +UIStateHelper::UIStateHelper(QObject *parent) : + QObject(parent) +{ +} + +UIStateHelper::~UIStateHelper() +{ + QMap::iterator it; + for (it = mData.begin(); it != mData.end(); ++it) { + delete(it.value()); + } +} + +UIStateHelperData *UIStateHelper::findData(int index, bool create) +{ + UIStateHelperData *data = NULL; + + QMap::iterator it = mData.find(index); + if (it == mData.end()) { + if (create) { + data = new UIStateHelperData; + mData[index] = data; + } + } else { + data = it.value(); + } + + return data; +} + +void UIStateHelper::addWidget(int index, QWidget *widget, UIStates states) +{ + UIStateHelperData *data = findData(index, true); + data->mWidgets.insert(widget, states); +} + +void UIStateHelper::addLoadPlaceholder(int index, QLabel *widget, bool clear, const QString &text) +{ + UIStateHelperData *data = findData(index, true); + data->mLoad.insert(UIStateHelperObject(widget), QPair(text.isEmpty() ? tr("Loading") : text, clear)); +} + +void UIStateHelper::addLoadPlaceholder(int index, QLineEdit *widget, bool clear, const QString &text) +{ + UIStateHelperData *data = findData(index, true); + data->mLoad.insert(UIStateHelperObject(widget), QPair(text.isEmpty() ? tr("Loading") : text, clear)); +} + +void UIStateHelper::addLoadPlaceholder(int index, RSTreeWidget *widget, bool clear, const QString &text) +{ + UIStateHelperData *data = findData(index, true); + data->mLoad.insert(UIStateHelperObject(widget), QPair(text.isEmpty() ? tr("Loading") : text, clear)); +} + +void UIStateHelper::addLoadPlaceholder(int index, LinkTextBrowser *widget, bool clear, const QString &text) +{ + UIStateHelperData *data = findData(index, true); + data->mLoad.insert(UIStateHelperObject(widget), QPair(text.isEmpty() ? tr("Loading") : text, clear)); +} + +void UIStateHelper::addClear(int index, QLabel *widget) +{ + UIStateHelperData *data = findData(index, true); + if (data->mClear.contains(widget)) { + return; + } + data->mClear.push_back(UIStateHelperObject(widget)); +} + +void UIStateHelper::addClear(int index, QLineEdit *widget) +{ + UIStateHelperData *data = findData(index, true); + if (data->mClear.contains(widget)) { + return; + } + data->mClear.push_back(UIStateHelperObject(widget)); +} + +void UIStateHelper::addClear(int index, RSTreeWidget *widget) +{ + UIStateHelperData *data = findData(index, true); + if (data->mClear.contains(widget)) { + return; + } + data->mClear.push_back(UIStateHelperObject(widget)); +} + +void UIStateHelper::addClear(int index, LinkTextBrowser *widget) +{ + UIStateHelperData *data = findData(index, true); + if (data->mClear.contains(widget)) { + return; + } + data->mClear.push_back(UIStateHelperObject(widget)); +} + +bool UIStateHelper::isWidgetVisible(QWidget *widget) +{ + bool visible = true; + + QMap::iterator itVisible = mWidgetVisible.find(widget); + if (itVisible != mWidgetVisible.end()) { + visible = itVisible.value(); + } + + if (visible) { + QMap::iterator dataIt; + for (dataIt = mData.begin(); dataIt != mData.end(); ++dataIt) { + UIStateHelperData *data = dataIt.value(); + QMap::iterator it = data->mWidgets.find(widget); + if (it == data->mWidgets.end()) { + continue; + } + + UIStates states = it.value(); + + if (states & (UISTATE_LOADING_VISIBLE | UISTATE_LOADING_INVISIBLE)) { + if (states & UISTATE_LOADING_VISIBLE) { + if (!data->mLoading) { + visible = false; + break; + } + } else if (states & UISTATE_LOADING_INVISIBLE) { + if (data->mLoading) { + visible = false; + break; + } + } + } + + if (states & (UISTATE_ACTIVE_VISIBLE | UISTATE_ACTIVE_INVISIBLE)) { + if (states & UISTATE_ACTIVE_VISIBLE) { + if (!data->mActive) { + visible = false; + break; + } + } else if (states & UISTATE_ACTIVE_INVISIBLE) { + if (data->mActive) { + visible = false; + break; + } + } + } + } + } + + return visible; +} + +bool UIStateHelper::isWidgetEnabled(QWidget *widget) +{ + bool enabled = true; + + QMap::iterator itEnabled = mWidgetEnabled.find(widget); + if (itEnabled != mWidgetEnabled.end()) { + enabled = itEnabled.value(); + } + + if (enabled) { + QMap::iterator dataIt; + for (dataIt = mData.begin(); dataIt != mData.end(); ++dataIt) { + UIStateHelperData *data = dataIt.value(); + QMap::iterator it = data->mWidgets.find(widget); + if (it == data->mWidgets.end()) { + continue; + } + + UIStates states = it.value(); + + if (states & (UISTATE_LOADING_ENABLED | UISTATE_LOADING_DISABLED)) { + if (states & UISTATE_LOADING_ENABLED) { + if (!data->mLoading) { + enabled = false; + break; + } + } else if (states & UISTATE_LOADING_DISABLED) { + if (data->mLoading) { + enabled = false; + break; + } + } + } + + if (states & (UISTATE_ACTIVE_ENABLED | UISTATE_ACTIVE_DISABLED)) { + if (states & UISTATE_ACTIVE_ENABLED) { + if (!data->mActive) { + enabled = false; + break; + } + } else if (states & UISTATE_ACTIVE_DISABLED) { + if (data->mActive) { + enabled = false; + break; + } + } + } + } + } + + return enabled; +} + +void UIStateHelper::updateData(UIStateHelperData *data) +{ + QMap::iterator it; + for (it = data->mWidgets.begin(); it != data->mWidgets.end(); ++it) { + QWidget *widget = it.key(); + UIStates states = it.value(); + + if (states & (UISTATE_LOADING_VISIBLE | UISTATE_LOADING_INVISIBLE | UISTATE_ACTIVE_VISIBLE | UISTATE_ACTIVE_INVISIBLE)) { + widget->setVisible(isWidgetVisible(widget)); + } + + if (states & (UISTATE_LOADING_ENABLED | UISTATE_LOADING_DISABLED | UISTATE_ACTIVE_ENABLED | UISTATE_ACTIVE_DISABLED)) { + widget->setEnabled(isWidgetEnabled(widget)); + } + } +} + +void UIStateHelper::setLoading(int index, bool loading) +{ + UIStateHelperData *data = findData(index, false); + if (!data) { + return; + } + data->mLoading = loading; + + updateData(data); + + QMap >::iterator it; + for (it = data->mLoad.begin(); it != data->mLoad.end(); ++it) { + if (loading) { + it.key().setPlaceholder(loading, it.value().first, it.value().second); + } else { + it.key().setPlaceholder(loading, "", it.value().second); + } + } +} + +void UIStateHelper::setActive(int index, bool active) +{ + UIStateHelperData *data = findData(index, false); + if (!data) { + return; + } + data->mActive = active; + + updateData(data); +} + +void UIStateHelper::clear(int index) +{ + UIStateHelperData *data = findData(index, false); + if (!data) { + return; + } + QList::iterator it; + for (it = data->mClear.begin(); it != data->mClear.end(); ++it) { + it->clear(); + } +} + +bool UIStateHelper::isLoading(int index) +{ + UIStateHelperData *data = findData(index, false); + if (data) { + return data->mLoading; + } + + return false; +} + +bool UIStateHelper::isActive(int index) +{ + UIStateHelperData *data = findData(index, false); + if (data) { + return data->mActive; + } + + return true; +} + +void UIStateHelper::setWidgetVisible(QWidget *widget, bool visible) +{ + mWidgetVisible[widget] = visible; + + QMap::iterator dataIt; + for (dataIt = mData.begin(); dataIt != mData.end(); ++dataIt) { + updateData(*dataIt); + } +} + +void UIStateHelper::setWidgetEnabled(QWidget *widget, bool enabled) +{ + mWidgetEnabled[widget] = enabled; + + QMap::iterator dataIt; + for (dataIt = mData.begin(); dataIt != mData.end(); ++dataIt) { + updateData(*dataIt); + } +} diff --git a/retroshare-gui/src/gui/common/UIStateHelper.h b/retroshare-gui/src/gui/common/UIStateHelper.h new file mode 100644 index 000000000..de0d538ea --- /dev/null +++ b/retroshare-gui/src/gui/common/UIStateHelper.h @@ -0,0 +1,95 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2013 RetroShare Team + * + * This program 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#ifndef UISTATEHELPER_H +#define UISTATEHELPER_H + +#include +#include + +class QWidget; +class QLabel; +class QLineEdit; +class RSTreeWidget; +class UIStateHelperData; +class LinkTextBrowser; + +enum UIState // State is untouched when bit is not set +{ + /* State for ::setLoading */ + UISTATE_LOADING_VISIBLE = 0x00000001, // visible when loading + UISTATE_LOADING_INVISIBLE = 0x00000002, // invisible when loading + UISTATE_LOADING_ENABLED = 0x00000004, // enabled when loading + UISTATE_LOADING_DISABLED = 0x00000008, // disabled when loading + /* State for ::setActive */ + UISTATE_ACTIVE_VISIBLE = 0x00000010, // visible when active + UISTATE_ACTIVE_INVISIBLE = 0x00000020, // invisible when active + UISTATE_ACTIVE_ENABLED = 0x00000040, // enabled when active + UISTATE_ACTIVE_DISABLED = 0x00000080 // disabled when active +}; +Q_DECLARE_FLAGS(UIStates, UIState) +Q_DECLARE_OPERATORS_FOR_FLAGS(UIStates) + +class UIStateHelper : public QObject +{ + Q_OBJECT + +public: + UIStateHelper(QObject *parent = 0); + ~UIStateHelper(); + + /* Add widgets */ + void addWidget(int index, QWidget *widget, UIStates states = UISTATE_LOADING_DISABLED | UISTATE_ACTIVE_ENABLED); + void addLoadPlaceholder(int index, QLabel *widget, bool clear = true, const QString &text = "" /* ="Loading" */); + void addLoadPlaceholder(int index, QLineEdit *widget, bool clear = true, const QString &text = "" /* ="Loading" */); + void addLoadPlaceholder(int index, RSTreeWidget *widget, bool clear = true, const QString &text = "" /* ="Loading" */); + void addLoadPlaceholder(int index, LinkTextBrowser *widget, bool clear = true, const QString &text = "" /* ="Loading" */); + void addClear(int index, QLabel *widget); + void addClear(int index, QLineEdit *widget); + void addClear(int index, RSTreeWidget *widget); + void addClear(int index, LinkTextBrowser *widget); + + /* Set state */ + void setLoading(int index, bool loading); + void setActive(int index, bool active); + void clear(int index); + + /* State */ + bool isLoading(int index); + bool isActive(int index); + + /* Set state of widget */ + void setWidgetVisible(QWidget *widget, bool visible); + void setWidgetEnabled(QWidget *widget, bool enabled); + +private: + UIStateHelperData *findData(int index, bool create); + void updateData(UIStateHelperData *data); + bool isWidgetVisible(QWidget *widget); + bool isWidgetEnabled(QWidget *widget); + +private: + QMap mData; + QMap mWidgetVisible; + QMap mWidgetEnabled; +}; + +#endif // UISTATEHELPER_H diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 528446aa7..df978d0fb 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -428,6 +428,7 @@ HEADERS += rshare.h \ gui/common/UserNotify.h \ gui/common/HeaderFrame.h \ gui/common/MimeTextEdit.h \ + gui/common/UIStateHelper.h \ gui/style/RSStyle.h \ gui/style/StyleDialog.h \ gui/MessagesDialog.h \ @@ -704,6 +705,7 @@ SOURCES += main.cpp \ gui/common/UserNotify.cpp \ gui/common/HeaderFrame.cpp \ gui/common/MimeTextEdit.cpp \ + gui/common/UIStateHelper.cpp \ gui/style/RSStyle.cpp \ gui/style/StyleDialog.cpp \ gui/settings/rsharesettings.cpp \ diff --git a/retroshare-gui/src/util/RsProtectedTimer.h b/retroshare-gui/src/util/RsProtectedTimer.h index fcf51cebc..323786ce1 100644 --- a/retroshare-gui/src/util/RsProtectedTimer.h +++ b/retroshare-gui/src/util/RsProtectedTimer.h @@ -23,6 +23,7 @@ #include #include +#include #define PROTECTED_TIMER_DEBUG @@ -45,7 +46,7 @@ class RsProtectedTimer: public QTimer } #ifdef PROTECTED_TIMER_DEBUG - std::cerr << "Timer has passsed protection." << std::endl; + std::cerr << "Timer has passed protection." << std::endl; #endif QTimer::timerEvent(e) ; }