From 719b414a82f3f53aa33bdcdaa0206463b18ca027 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 3 Jul 2017 22:32:08 +0200 Subject: [PATCH 01/35] fixed merging of comments in channel post with async-ed loading system --- retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp | 13 ++++++++++++- retroshare-gui/src/gui/feeds/GxsChannelPostItem.h | 8 +++++++- .../src/gui/gxschannels/GxsChannelPostsWidget.cpp | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index 53fc4830f..93107d649 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -46,9 +46,20 @@ #define COLOR_NORMAL QColor(248, 248, 248) #define COLOR_NEW QColor(220, 236, 253) -GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) : +GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate,const std::set& older_versions) : GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsGxsChannels, autoUpdate) { + QVector v; + bool self = false; + + for(std::set::const_iterator it(older_versions.begin());it!=older_versions.end();++it) + v.push_back(*it) ; + + if(older_versions.find(messageId) == older_versions.end()) + v.push_back(messageId); + + setMessageVersions(v) ; + setup(); mLoaded = false ; diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index 32f8b0b06..96d2f499e 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -42,7 +42,10 @@ class GxsChannelPostItem : public GxsFeedItem public: // This one is used in NewFeed for incoming channel posts. Only the group and msg ids are known at this point. - GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate); + // It can be used for all apparences of channel posts. But in rder to merge comments from the previous versions of the post, the list of + // previous posts should be supplied. It's optional. If not supplied only the comments of the new version will be displayed. + + GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate, const std::set& older_versions = std::set()); //GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup &group, const RsGxsChannelPost &post, bool isHome, bool autoUpdate); //GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost &post, bool isHome, bool autoUpdate); @@ -64,6 +67,9 @@ protected: virtual void doExpand(bool open); virtual void expandFill(bool first); + // This does nothing except triggering the loading of the post data and comments. This function is mainly used to detect + // when the post is actually made visible. + virtual void paintEvent(QPaintEvent *); /* GxsGroupFeedItem */ diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index f78bc339a..12f5b5e85 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -412,7 +412,7 @@ void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost &post, bool re //dummyGroup.mMeta.mSubscribeFlags = 0xffffffff; //GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, dummyGroup, post, true, false); - GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, post.mMeta.mGroupId, post.mMeta.mMsgId, true, true); + GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, post.mMeta.mGroupId, post.mMeta.mMsgId, true, false,post.mOlderVersions); ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(post.mMeta.mPublishTs)); return ; @@ -435,7 +435,7 @@ void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost &post, bool re //dummyGroup.mMeta.mSubscribeFlags = 0xffffffff; //GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, dummyGroup, post, true, false); - GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, post.mMeta.mGroupId, post.mMeta.mMsgId, true, true); + GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, post.mMeta.mGroupId, post.mMeta.mMsgId, true, false,post.mOlderVersions); ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(post.mMeta.mPublishTs)); } From 1dea00d2cbbaf7b6867e8eabd3a70c144be22e3d Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 3 Jul 2017 23:09:17 +0200 Subject: [PATCH 02/35] attempt to fix channel post auto-size by limiting the number of lines from message to display in summary depending on available size --- .../src/gui/feeds/GxsChannelPostItem.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index 93107d649..4db137ff3 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -382,6 +382,14 @@ void GxsChannelPostItem::fill() QString title; + if(mPost.mThumbnail.mData != NULL) + { + QPixmap thumbnail; + thumbnail.loadFromData(mPost.mThumbnail.mData, mPost.mThumbnail.mSize, "PNG"); + // Wiping data - as its been passed to thumbnail. + ui->logoLabel->setPixmap(thumbnail); + } + if (!mIsHome) { if (mCloseOnRead && !IS_MSG_NEW(mPost.mMeta.mMsgStatus)) { @@ -419,9 +427,12 @@ void GxsChannelPostItem::fill() /* subject */ ui->titleLabel->setText(QString::fromUtf8(mPost.mMeta.mMsgName.c_str())); + uint32_t autorized_lines = (int)floor((ui->logoLabel->height() - ui->titleLabel->height() - ui->buttonHLayout->sizeHint().height())/QFontMetricsF(ui->subjectLabel->font()).height()); + // fill first 4 lines of message. (csoler) Disabled the replacement of smileys and links, because the cost is too crazy - //ui->subjectLabel->setText(RsHtml().formatText(NULL, RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 4), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); - ui->subjectLabel->setText(RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 4)) ; + ui->subjectLabel->setText(RsHtml().formatText(NULL, RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), autorized_lines), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); + + //ui->subjectLabel->setText(RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 2)) ; //QString score = QString::number(post.mTopScore); // scoreLabel->setText(score); @@ -529,14 +540,6 @@ void GxsChannelPostItem::fill() layout->addWidget(fi); } - if(mPost.mThumbnail.mData != NULL) - { - QPixmap thumbnail; - thumbnail.loadFromData(mPost.mThumbnail.mData, mPost.mThumbnail.mSize, "PNG"); - // Wiping data - as its been passed to thumbnail. - ui->logoLabel->setPixmap(thumbnail); - } - mInFill = false; } From 931ddaef7950ce65c5b442fb4305dfc72656b7e7 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Jul 2017 23:13:03 +0200 Subject: [PATCH 03/35] set load thread to false for channels on default. Fixed missing () in connect --- retroshare-gui/src/gui/settings/ChannelPage.cpp | 7 +++++-- retroshare-gui/src/gui/settings/rsharesettings.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/settings/ChannelPage.cpp b/retroshare-gui/src/gui/settings/ChannelPage.cpp index 199dd5b3a..eff89a5e5 100644 --- a/retroshare-gui/src/gui/settings/ChannelPage.cpp +++ b/retroshare-gui/src/gui/settings/ChannelPage.cpp @@ -33,10 +33,13 @@ ChannelPage::ChannelPage(QWidget * parent, Qt::WindowFlags flags) ui.groupFrameSettingsWidget->setOpenAllInNewTabText(tr("Open each channel in a new tab")); ui.groupFrameSettingsWidget->setType(GroupFrameSettings::Channel) ; - connect(ui.loadThreadCheckBox,SIGNAL(toggled(bool)),this,SLOT(updateLoadThread)) ; + connect(ui.loadThreadCheckBox,SIGNAL(toggled(bool)),this,SLOT(updateLoadThread())) ; } -void ChannelPage::updateLoadThread() { Settings->setChannelLoadThread(ui.loadThreadCheckBox->isChecked()); } +void ChannelPage::updateLoadThread() +{ + Settings->setChannelLoadThread(ui.loadThreadCheckBox->isChecked()); +} ChannelPage::~ChannelPage() { diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index f550c66be..1ad2a76d3 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -1066,7 +1066,7 @@ void RshareSettings::setForumLoadEmoticons(bool value) /* Channel */ bool RshareSettings::getChannelLoadThread() { - return valueFromGroup("Channel", "LoadThread", true).toBool(); + return valueFromGroup("Channel", "LoadThread", false).toBool(); } void RshareSettings::setChannelLoadThread(bool value) From 5f7df7cb736125183fe522e02833f25d0e2a9efb Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Jul 2017 23:26:57 +0200 Subject: [PATCH 04/35] update call to notifySettingsChanged() when changing the thread loading of channels --- retroshare-gui/src/gui/settings/ChannelPage.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/retroshare-gui/src/gui/settings/ChannelPage.cpp b/retroshare-gui/src/gui/settings/ChannelPage.cpp index eff89a5e5..27f71e8e6 100644 --- a/retroshare-gui/src/gui/settings/ChannelPage.cpp +++ b/retroshare-gui/src/gui/settings/ChannelPage.cpp @@ -22,6 +22,7 @@ #include "ChannelPage.h" #include "rsharesettings.h" #include "util/misc.h" +#include "gui/notifyqt.h" ChannelPage::ChannelPage(QWidget * parent, Qt::WindowFlags flags) : ConfigPage(parent, flags) @@ -39,6 +40,7 @@ ChannelPage::ChannelPage(QWidget * parent, Qt::WindowFlags flags) void ChannelPage::updateLoadThread() { Settings->setChannelLoadThread(ui.loadThreadCheckBox->isChecked()); + NotifyQt::getInstance()->notifySettingsChanged(); } ChannelPage::~ChannelPage() From c1e18c7fe64b2076934f807cb57206d3559e2cb3 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Jul 2017 22:12:56 +0200 Subject: [PATCH 05/35] fixed bug causing an infinite subscribe/unsubscribe loop in GxsTrans --- libretroshare/src/gxs/rsgenexchange.cc | 44 ++++++++++++++---------- libretroshare/src/gxstrans/p3gxstrans.cc | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index e48988e33..eae9dab4d 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1188,26 +1188,30 @@ bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list metaL; bool ok = mDataAccess->getGroupSummary(token, metaL); - std::list::iterator lit = metaL.begin(); RsGroupMetaData m; - for(; lit != metaL.end(); ++lit) + + for( std::list::iterator lit = metaL.begin(); lit != metaL.end(); ++lit) { RsGxsGrpMetaData& gMeta = *(*lit); + m = gMeta; RsGroupNetworkStats sts ; - if(mNetService != NULL && mNetService->getGroupNetworkStats((*lit)->mGroupId,sts)) - { - m.mPop = sts.mSuppliers ; - m.mVisibleMsgCount = sts.mMaxVisibleCount ; - } - else - { - m.mPop= 0 ; - m.mVisibleMsgCount = 0 ; - } + if(mNetService != NULL && mNetService->getGroupNetworkStats(gMeta.mGroupId,sts)) + { + m.mPop = sts.mSuppliers ; + m.mVisibleMsgCount = sts.mMaxVisibleCount ; - groupInfo.push_back(m); + if((!(IS_GROUP_SUBSCRIBED(gMeta.mSubscribeFlags))) || gMeta.mLastPost == 0) + m.mLastPost = sts.mLastGroupModificationTS ; + } + else + { + m.mPop= 0 ; + m.mVisibleMsgCount = 0 ; + } + + groupInfo.push_back(m); delete (*lit); } @@ -1369,6 +1373,14 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vectormeta.mPop = sts.mSuppliers; gItem->meta.mVisibleMsgCount = sts.mMaxVisibleCount; + + // When the group is not subscribed, the last post value is not updated, because there's no message stored. As a consequence, + // we rely on network statistics to give this value, but it is not as accurate as if it was locally computed, because of blocked + // posts, friends not available, sync delays, etc. Similarly if the group has just been subscribed, the last post info is probably + // uninitialised, so we will it too. + + if((!(IS_GROUP_SUBSCRIBED(gItem->meta.mSubscribeFlags))) || gItem->meta.mLastPost == 0) + gItem->meta.mLastPost = sts.mLastGroupModificationTS ; } else { @@ -1376,12 +1388,6 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vectormeta.mVisibleMsgCount = 0; } - // When the group is not subscribed, the last post value is not updated, because there's no message stored. As a consequence, - // we rely on network statistics to give this value, but it is not as accurate as if it was locally computed, because of blocked - // posts, friends not available, sync delays, etc. - - if(!(IS_GROUP_SUBSCRIBED(gItem->meta.mSubscribeFlags))) - gItem->meta.mLastPost = sts.mLastGroupModificationTS ; // Also check the group privacy flags. A while ago, it as possible to publish a group without privacy flags. Now it is not possible anymore. // As a consequence, it's important to supply a correct value in this flag before the data can be edited/updated. diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index 382397c2e..a5a5379ce 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -20,7 +20,7 @@ #include "gxstrans/p3gxstrans.h" #include "util/stacktrace.h" -//#define DEBUG_GXSTRANS 1 +#define DEBUG_GXSTRANS 1 typedef unsigned int uint; From 141277b131d862919d22d1c131ef8cab5deaf5e6 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Jul 2017 22:16:14 +0200 Subject: [PATCH 06/35] removed debug info --- libretroshare/src/gxstrans/p3gxstrans.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index a5a5379ce..382397c2e 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -20,7 +20,7 @@ #include "gxstrans/p3gxstrans.h" #include "util/stacktrace.h" -#define DEBUG_GXSTRANS 1 +//#define DEBUG_GXSTRANS 1 typedef unsigned int uint; From 8e62a8b1b259779fb60edf9037584d720b5bbdea Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Jul 2017 22:32:54 +0200 Subject: [PATCH 07/35] updated tooltip for opinion in People --- retroshare-gui/src/gui/Identity/IdDialog.ui | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.ui b/retroshare-gui/src/gui/Identity/IdDialog.ui index 1c52802ef..b75154361 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.ui +++ b/retroshare-gui/src/gui/Identity/IdDialog.ui @@ -6,8 +6,8 @@ 0 0 - 1048 - 779 + 1573 + 1177 @@ -283,8 +283,8 @@ 0 0 - 717 - 692 + 1372 + 1000 @@ -569,8 +569,9 @@ border-image: url(:/images/closepressed.png) <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Your own opinion about an identity rules the visibility of that identity for yourself and your friend nodes. Your own opinion is shared among friends and used to compute a reputation score: If your opinion about an identity is neutral, the reputation score is the average of your friend's opinions. If not, your own opinion gives the score.</p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The overall score is used in chat lobbies, forums and channels to decide on the actions to take for each specific identity. When the overall score is lower than -0.6, the identity is banned, which prevents all messages and forums/channels authored by this identity to be forwarded, both ways. Some forums also have special anti-spam flags that require a higher reputation level, making them more sensitive to bad opinions. Banned identities gradually lose their activity and eventually disappear (after 30 days). </p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Your own opinion about an identity rules the visibility of that identity for yourself and your friend nodes. Your own opinion is shared among friends and used to compute a reputation score: If your opinion about an identity is neutral, the reputation score is the difference between friend's positive and negative opinions. If not, your own opinion gives the score.</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The overall score is used in chat lobbies, forums and channels to decide on the actions to take for each specific identity. When the overall score is lower than -1, the identity is banned, which prevents all messages and forums/channels authored by this identity to be forwarded, both ways. Some forums also have special anti-spam flags that require a non negative reputation level, making them more sensitive to bad opinions. Banned identities gradually lose their activity and eventually disappear (after 5 days).</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">You can change the thresholds and the time of inactivity to delete identities in preferences -&gt; people. </p> <p style="-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> From aca6233dbfbaad9a22206755a3caad3a8850b814 Mon Sep 17 00:00:00 2001 From: Konrad Date: Thu, 6 Jul 2017 14:05:48 +0200 Subject: [PATCH 08/35] Added: Handling requests to invite peers to lobby --- libresapi/src/api/ChatHandler.cpp | 20 ++++++++++++++++++++ libresapi/src/api/ChatHandler.h | 1 + 2 files changed, 21 insertions(+) diff --git a/libresapi/src/api/ChatHandler.cpp b/libresapi/src/api/ChatHandler.cpp index 1a5fd6e6c..6809e2435 100644 --- a/libresapi/src/api/ChatHandler.cpp +++ b/libresapi/src/api/ChatHandler.cpp @@ -169,6 +169,7 @@ ChatHandler::ChatHandler(StateTokenServer *sts, RsNotify *notify, RsMsgs *msgs, addResourceHandler("unsubscribe_lobby", this, &ChatHandler::handleUnsubscribeLobby); addResourceHandler("autosubscribe_lobby", this, &ChatHandler::handleAutoSubsribeLobby); addResourceHandler("clear_lobby", this, &ChatHandler::handleClearLobby); + addResourceHandler("invite_to_lobby", this, &ChatHandler::handleInviteToLobby); addResourceHandler("lobby_participants", this, &ChatHandler::handleLobbyParticipants); addResourceHandler("messages", this, &ChatHandler::handleMessages); addResourceHandler("send_message", this, &ChatHandler::handleSendMessage); @@ -936,6 +937,25 @@ void ChatHandler::handleClearLobby(Request &req, Response &resp) resp.setOk(); } +void ChatHandler::handleInviteToLobby(Request& req, Response& resp) +{ + std::string chat_id; + std::string pgp_id; + req.mStream << makeKeyValueReference("chat_id", chat_id); + req.mStream << makeKeyValueReference("pgp_id", pgp_id); + + ChatId chatId(chat_id); + RsPgpId pgpId(pgp_id); + + std::list peerIds; + mRsPeers->getAssociatedSSLIds(pgpId, peerIds); + + for(std::list::iterator it = peerIds.begin(); it != peerIds.end(); it++) + mRsMsgs->invitePeerToLobby(chatId.toLobbyId(), (*it)); + + resp.setOk(); +} + ResponseTask* ChatHandler::handleLobbyParticipants(Request &req, Response &resp) { RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ diff --git a/libresapi/src/api/ChatHandler.h b/libresapi/src/api/ChatHandler.h index 9cda3e551..8f237b401 100644 --- a/libresapi/src/api/ChatHandler.h +++ b/libresapi/src/api/ChatHandler.h @@ -122,6 +122,7 @@ private: void handleSubscribeLobby(Request& req, Response& resp); void handleUnsubscribeLobby(Request& req, Response& resp); void handleAutoSubsribeLobby(Request& req, Response& resp); + void handleInviteToLobby(Request& req, Response& resp); void handleClearLobby(Request& req, Response& resp); ResponseTask* handleLobbyParticipants(Request& req, Response& resp); void handleMessages(Request& req, Response& resp); From c9bfe4b526b8fdd3027decc6316e2dc632364cee Mon Sep 17 00:00:00 2001 From: Konrad Date: Thu, 6 Jul 2017 14:07:33 +0200 Subject: [PATCH 09/35] Added: Handling requests to get lobbies invitations --- libresapi/src/api/ChatHandler.cpp | 30 ++++++++++++++++++++++++++++++ libresapi/src/api/ChatHandler.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/libresapi/src/api/ChatHandler.cpp b/libresapi/src/api/ChatHandler.cpp index 6809e2435..7aed53dc1 100644 --- a/libresapi/src/api/ChatHandler.cpp +++ b/libresapi/src/api/ChatHandler.cpp @@ -161,6 +161,7 @@ ChatHandler::ChatHandler(StateTokenServer *sts, RsNotify *notify, RsMsgs *msgs, mMsgStateToken = mStateTokenServer->getNewToken(); mLobbiesStateToken = mStateTokenServer->getNewToken(); mUnreadMsgsStateToken = mStateTokenServer->getNewToken(); + mInvitationsStateToken = mStateTokenServer->getNewToken(); addResourceHandler("*", this, &ChatHandler::handleWildcard); addResourceHandler("lobbies", this, &ChatHandler::handleLobbies); @@ -170,6 +171,7 @@ ChatHandler::ChatHandler(StateTokenServer *sts, RsNotify *notify, RsMsgs *msgs, addResourceHandler("autosubscribe_lobby", this, &ChatHandler::handleAutoSubsribeLobby); addResourceHandler("clear_lobby", this, &ChatHandler::handleClearLobby); addResourceHandler("invite_to_lobby", this, &ChatHandler::handleInviteToLobby); + addResourceHandler("get_invitations_to_lobby", this, &ChatHandler::handleGetInvitationsToLobby); addResourceHandler("lobby_participants", this, &ChatHandler::handleLobbyParticipants); addResourceHandler("messages", this, &ChatHandler::handleMessages); addResourceHandler("send_message", this, &ChatHandler::handleSendMessage); @@ -230,6 +232,15 @@ void ChatHandler::notifyChatLobbyEvent(uint64_t lobby_id, uint32_t event_type, } } +void ChatHandler::notifyListChange(int list, int type) +{ + if(list == NOTIFY_LIST_CHAT_LOBBY_INVITATION) + { + RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + mStateTokenServer->replaceToken(mInvitationsStateToken); + } +} + void ChatHandler::tick() { RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ @@ -956,6 +967,25 @@ void ChatHandler::handleInviteToLobby(Request& req, Response& resp) resp.setOk(); } +void ChatHandler::handleGetInvitationsToLobby(Request& req, Response& resp) +{ + std::list invites; + mRsMsgs->getPendingChatLobbyInvites(invites); + + resp.mDataStream.getStreamToMember(); + for(std::list::const_iterator it = invites.begin(); it != invites.end(); ++it) + { + resp.mDataStream.getStreamToMember() + << makeKeyValue("peer_id", (*it).peer_id.toStdString()) + << makeKeyValue("lobby_id", (*it).lobby_id) + << makeKeyValue("lobby_name", (*it).lobby_name) + << makeKeyValue("lobby_topic", (*it).lobby_topic); + } + + resp.mStateToken = mInvitationsStateToken; + resp.setOk(); +} + ResponseTask* ChatHandler::handleLobbyParticipants(Request &req, Response &resp) { RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ diff --git a/libresapi/src/api/ChatHandler.h b/libresapi/src/api/ChatHandler.h index 8f237b401..f8f5461e5 100644 --- a/libresapi/src/api/ChatHandler.h +++ b/libresapi/src/api/ChatHandler.h @@ -35,6 +35,8 @@ public: virtual void notifyChatLobbyEvent (uint64_t /* lobby id */, uint32_t /* event type */ , const RsGxsId& /* nickname */,const std::string& /* any string */); + virtual void notifyListChange(int list, int type); + // from tickable virtual void tick(); @@ -123,6 +125,7 @@ private: void handleUnsubscribeLobby(Request& req, Response& resp); void handleAutoSubsribeLobby(Request& req, Response& resp); void handleInviteToLobby(Request& req, Response& resp); + void handleGetInvitationsToLobby(Request& req, Response& resp); void handleClearLobby(Request& req, Response& resp); ResponseTask* handleLobbyParticipants(Request& req, Response& resp); void handleMessages(Request& req, Response& resp); @@ -163,6 +166,7 @@ private: std::map mLobbyParticipantsInfos; StateToken mUnreadMsgsStateToken; + StateToken mInvitationsStateToken; }; } // namespace resource_api From 11d02f461260d347c2f3c4614e15f64a53764852 Mon Sep 17 00:00:00 2001 From: Konrad Date: Thu, 6 Jul 2017 14:08:50 +0200 Subject: [PATCH 10/35] Added: Handling requests to answer invitation to lobby --- libresapi/src/api/ChatHandler.cpp | 27 +++++++++++++++++++++++++++ libresapi/src/api/ChatHandler.h | 1 + 2 files changed, 28 insertions(+) diff --git a/libresapi/src/api/ChatHandler.cpp b/libresapi/src/api/ChatHandler.cpp index 7aed53dc1..00c5c7fb2 100644 --- a/libresapi/src/api/ChatHandler.cpp +++ b/libresapi/src/api/ChatHandler.cpp @@ -172,6 +172,7 @@ ChatHandler::ChatHandler(StateTokenServer *sts, RsNotify *notify, RsMsgs *msgs, addResourceHandler("clear_lobby", this, &ChatHandler::handleClearLobby); addResourceHandler("invite_to_lobby", this, &ChatHandler::handleInviteToLobby); addResourceHandler("get_invitations_to_lobby", this, &ChatHandler::handleGetInvitationsToLobby); + addResourceHandler("answer_to_invitation", this, &ChatHandler::handleAnswerToInvitation); addResourceHandler("lobby_participants", this, &ChatHandler::handleLobbyParticipants); addResourceHandler("messages", this, &ChatHandler::handleMessages); addResourceHandler("send_message", this, &ChatHandler::handleSendMessage); @@ -986,6 +987,32 @@ void ChatHandler::handleGetInvitationsToLobby(Request& req, Response& resp) resp.setOk(); } +void ChatHandler::handleAnswerToInvitation(Request& req, Response& resp) +{ + ChatLobbyId lobbyId = 0; + req.mStream << makeKeyValueReference("lobby_id", lobbyId); + + bool join; + req.mStream << makeKeyValueReference("join", join); + + std::string gxs_id; + req.mStream << makeKeyValueReference("gxs_id", gxs_id); + RsGxsId gxsId(gxs_id); + + if(join) + { + if(rsMsgs->acceptLobbyInvite(lobbyId, gxsId)) + resp.setOk(); + else + resp.setFail(); + } + else + { + rsMsgs->denyLobbyInvite(lobbyId); + resp.setOk(); + } +} + ResponseTask* ChatHandler::handleLobbyParticipants(Request &req, Response &resp) { RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ diff --git a/libresapi/src/api/ChatHandler.h b/libresapi/src/api/ChatHandler.h index f8f5461e5..cac28271d 100644 --- a/libresapi/src/api/ChatHandler.h +++ b/libresapi/src/api/ChatHandler.h @@ -126,6 +126,7 @@ private: void handleAutoSubsribeLobby(Request& req, Response& resp); void handleInviteToLobby(Request& req, Response& resp); void handleGetInvitationsToLobby(Request& req, Response& resp); + void handleAnswerToInvitation(Request& req, Response& resp); void handleClearLobby(Request& req, Response& resp); ResponseTask* handleLobbyParticipants(Request& req, Response& resp); void handleMessages(Request& req, Response& resp); From b935bacd9946c88832e967f2b1605e517622d093 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Thu, 6 Jul 2017 16:28:00 +0200 Subject: [PATCH 11/35] Add missing break in p3IdService::handleResponse --- libretroshare/src/services/p3idservice.cc | 51 +++++++++++------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 2e3da2a2b..a1dfc51d5 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -4397,32 +4397,31 @@ void p3IdService::handleResponse(uint32_t token, uint32_t req_type) // stuff. switch(req_type) { - case GXSIDREQ_CACHEOWNIDS: - cache_load_ownids(token); - break; - case GXSIDREQ_CACHELOAD: - cache_load_for_token(token); - break; - case GXSIDREQ_PGPHASH: - pgphash_handlerequest(token); - break; - case GXSIDREQ_RECOGN: - recogn_handlerequest(token); - break; - case GXSIDREQ_CACHETEST: - cachetest_handlerequest(token); - break; - case GXSIDREQ_OPINION: - opinion_handlerequest(token); - break; - case GXSIDREQ_SERIALIZE_TO_MEMORY: - handle_get_serialized_grp(token) ; - - default: - /* error */ - std::cerr << "p3IdService::handleResponse() Unknown Request Type: " << req_type; - std::cerr << std::endl; - break; + case GXSIDREQ_CACHEOWNIDS: + cache_load_ownids(token); + break; + case GXSIDREQ_CACHELOAD: + cache_load_for_token(token); + break; + case GXSIDREQ_PGPHASH: + pgphash_handlerequest(token); + break; + case GXSIDREQ_RECOGN: + recogn_handlerequest(token); + break; + case GXSIDREQ_CACHETEST: + cachetest_handlerequest(token); + break; + case GXSIDREQ_OPINION: + opinion_handlerequest(token); + break; + case GXSIDREQ_SERIALIZE_TO_MEMORY: + handle_get_serialized_grp(token); + break; + default: + std::cerr << "p3IdService::handleResponse() Unknown Request Type: " + << req_type << std::endl; + break; } } From c630f1fa89c567e03c690c5738ea00d175ff8ed7 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Thu, 6 Jul 2017 16:28:59 +0200 Subject: [PATCH 12/35] Fix unused warning in gxstokenqueue --- libretroshare/src/gxs/gxstokenqueue.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/gxs/gxstokenqueue.cc b/libretroshare/src/gxs/gxstokenqueue.cc index e0cbdf46d..b857ee1a8 100644 --- a/libretroshare/src/gxs/gxstokenqueue.cc +++ b/libretroshare/src/gxs/gxstokenqueue.cc @@ -31,7 +31,7 @@ bool GxsTokenQueue::queueRequest(uint32_t token, uint32_t req_type) { - RsStackMutex stack(mQueueMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mQueueMtx); mQueue.push_back(GxsTokenQueueItem(token, req_type)); return true; } From 54047cd7a76431ade2f9cd21ab9104f263a9a22d Mon Sep 17 00:00:00 2001 From: Phenom Date: Thu, 6 Jul 2017 22:35:54 +0200 Subject: [PATCH 13/35] Fix multi download of same file. --- libretroshare/src/ft/ftcontroller.cc | 2 +- retroshare-gui/src/gui/RetroShareLink.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index b50a52ed3..a349f8d1b 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -868,7 +868,7 @@ bool ftController::alreadyHaveFile(const RsFileHash& hash, FileInfo &info) return true ; // check for file lists - if (mSearch) return false; + if (!mSearch) return false; if (mSearch->search(hash, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info)) return true ; diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index c3d2c0450..3c64e9021 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -1275,8 +1275,10 @@ static void processList(const QStringList &list, const QString &textSingular, co /* make path for downloaded file */ std::string path; path = fi.path;//Shared files has path with filename included - if (fi.downloadStatus == FT_STATE_COMPLETE) - path = fi.path + "/" + fi.fname; + + //Seems that all FileInfo get .path==filepath+filename + //if (fi.downloadStatus == FT_STATE_COMPLETE) + // path = fi.path + "/" + fi.fname; QFileInfo qinfo; qinfo.setFile(QString::fromUtf8(path.c_str())); From f0ad68789b10122fc3c34e23d7d848517d4ba4c5 Mon Sep 17 00:00:00 2001 From: Konrad Date: Thu, 6 Jul 2017 22:44:45 +0200 Subject: [PATCH 14/35] Fixed: Libresapi was throwing exception when requested to add new cert which was empty --- libresapi/src/api/PeersHandler.cpp | 35 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/libresapi/src/api/PeersHandler.cpp b/libresapi/src/api/PeersHandler.cpp index 4631ccf7c..d71ceaf81 100644 --- a/libresapi/src/api/PeersHandler.cpp +++ b/libresapi/src/api/PeersHandler.cpp @@ -601,19 +601,30 @@ void PeersHandler::handleWildcard(Request &req, Response &resp) } RsPeerId peer_id; RsPgpId pgp_id; + std::string cleanCert; + int error_code; std::string error_string; - if(mRsPeers->loadCertificateFromString(cert_string, peer_id, pgp_id, error_string) - && mRsPeers->addFriend(peer_id, pgp_id, flags)) - { - ok = true; - resp.mDataStream << makeKeyValueReference("pgp_id", pgp_id); - resp.mDataStream << makeKeyValueReference("peer_id", peer_id); - } - else - { - resp.mDebug << "Error: failed to add peer" << std::endl; - resp.mDebug << error_string << std::endl; - } + + if (mRsPeers->cleanCertificate(cert_string, cleanCert, error_code)) + { + if(mRsPeers->loadCertificateFromString(cert_string, peer_id, pgp_id, error_string) + && mRsPeers->addFriend(peer_id, pgp_id, flags)) + { + ok = true; + resp.mDataStream << makeKeyValueReference("pgp_id", pgp_id); + resp.mDataStream << makeKeyValueReference("peer_id", peer_id); + } + else + { + resp.mDebug << "Error: failed to add peer" << std::endl; + resp.mDebug << error_string << std::endl; + } + } + else + { + resp.mDebug << "Error: failed to add peer" << std::endl; + resp.mDebug << error_code << std::endl; + } } } if(ok) From 2cb6742dbcc56eeb8fba5d27f85d49582ffa9ff3 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Mon, 10 Jul 2017 19:50:11 +0200 Subject: [PATCH 15/35] Create logic for call android native image picker --- retroshare-qml-app/src/ContactDetails.qml | 9 ++++++ .../src/android/AndroidManifest.xml | 14 ++++++++++ .../qml_app/RetroshareImagePicker.java | 23 +++++++++++++++ retroshare-qml-app/src/androidimagepicker.h | 28 +++++++++++++++++++ retroshare-qml-app/src/main-app.cpp | 11 ++++++++ retroshare-qml-app/src/retroshare-qml-app.pro | 3 +- 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroshareImagePicker.java create mode 100644 retroshare-qml-app/src/androidimagepicker.h diff --git a/retroshare-qml-app/src/ContactDetails.qml b/retroshare-qml-app/src/ContactDetails.qml index 7b7cfedf8..f3d3b6697 100644 --- a/retroshare-qml-app/src/ContactDetails.qml +++ b/retroshare-qml-app/src/ContactDetails.qml @@ -27,6 +27,15 @@ Item property var md property bool is_contact: cntDt.md.is_contact + Button + { + text: "Open f d " + onClicked: + { + androidImagePicker.openPicker() + } + } + ColorHash { id: colorHash diff --git a/retroshare-qml-app/src/android/AndroidManifest.xml b/retroshare-qml-app/src/android/AndroidManifest.xml index f7bb601cb..7f7913dd2 100644 --- a/retroshare-qml-app/src/android/AndroidManifest.xml +++ b/retroshare-qml-app/src/android/AndroidManifest.xml @@ -83,6 +83,18 @@ + + + + + + + + @@ -206,4 +218,6 @@ + + diff --git a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroshareImagePicker.java b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroshareImagePicker.java new file mode 100644 index 000000000..c2a2c5739 --- /dev/null +++ b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroshareImagePicker.java @@ -0,0 +1,23 @@ +package org.retroshare.android.qml_app; + +/** + * Created by Angesoc on 10/07/17. + */ + +import org.qtproject.qt5.android.bindings.QtActivity; +import android.content.Intent; +import android.provider.MediaStore; +import android.util.Log; + + +public class RetroshareImagePicker extends QtActivity{ + + public static Intent imagePickerIntent() { + + Log.i("RetroshareImagePicker", "imagePickerIntent()"); + + Intent intent = new Intent( Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI ); + intent.setType("image/*"); + return Intent.createChooser(intent, "Select Image"); + } +} diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h new file mode 100644 index 000000000..d30026701 --- /dev/null +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include + +#ifdef __ANDROID__ +# include +# include +#endif // __ANDROID__ + +struct AndroidImagePicker : QObject +{ + Q_OBJECT + +public slots: + + static void openPicker() + { + qDebug() << "Starting image picker intent"; + + #ifdef __ANDROID__ + QAndroidJniObject::callStaticMethod( + "org/retroshare/android/qml_app/RetroshareImagePicker", + "imagePickerIntent", + "()Landroid/content/Intent;" ); + #endif // __ANDROID__ + } +}; diff --git a/retroshare-qml-app/src/main-app.cpp b/retroshare-qml-app/src/main-app.cpp index 52dd19962..6c66961b1 100644 --- a/retroshare-qml-app/src/main-app.cpp +++ b/retroshare-qml-app/src/main-app.cpp @@ -34,6 +34,8 @@ #include "libresapilocalclient.h" #include "rsqmlappengine.h" +#include "androidimagepicker.h" + int main(int argc, char *argv[]) { @@ -46,6 +48,7 @@ int main(int argc, char *argv[]) "org.retroshare.qml_components.LibresapiLocalClient", 1, 0, "LibresapiLocalClient"); + QString sockPath = QDir::homePath() + "/.retroshare"; sockPath.append("/libresapi.sock"); @@ -55,6 +58,14 @@ int main(int argc, char *argv[]) RsQmlAppEngine engine(true); QQmlContext& rootContext = *engine.rootContext(); + qmlRegisterType( + "org.retroshare.qml_components.AndroidImagePicker", 1, 0, + "AndroidImagePicker"); + + AndroidImagePicker androidImagePicker; + engine.rootContext()->setContextProperty("androidImagePicker", + &androidImagePicker); + QStringList mainArgs = app.arguments(); #ifdef Q_OS_ANDROID diff --git a/retroshare-qml-app/src/retroshare-qml-app.pro b/retroshare-qml-app/src/retroshare-qml-app.pro index 338935419..9aad93153 100644 --- a/retroshare-qml-app/src/retroshare-qml-app.pro +++ b/retroshare-qml-app/src/retroshare-qml-app.pro @@ -5,7 +5,8 @@ QT += core network qml quick CONFIG += c++11 HEADERS += libresapilocalclient.h \ - rsqmlappengine.h + rsqmlappengine.h \ + androidimagepicker.h SOURCES += main-app.cpp \ libresapilocalclient.cpp \ rsqmlappengine.cpp From 3b092f7fb6af605bccd9c9efa19d20436c376670 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 11 Jul 2017 17:34:06 +0200 Subject: [PATCH 16/35] Delete imagepicker activity --- .../src/android/AndroidManifest.xml | 14 ++--------- .../qml_app/RetroshareImagePicker.java | 23 ------------------- 2 files changed, 2 insertions(+), 35 deletions(-) delete mode 100644 retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroshareImagePicker.java diff --git a/retroshare-qml-app/src/android/AndroidManifest.xml b/retroshare-qml-app/src/android/AndroidManifest.xml index 7f7913dd2..c6323fe84 100644 --- a/retroshare-qml-app/src/android/AndroidManifest.xml +++ b/retroshare-qml-app/src/android/AndroidManifest.xml @@ -83,18 +83,6 @@ - - - - - - - - @@ -220,4 +208,6 @@ + + diff --git a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroshareImagePicker.java b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroshareImagePicker.java deleted file mode 100644 index c2a2c5739..000000000 --- a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroshareImagePicker.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.retroshare.android.qml_app; - -/** - * Created by Angesoc on 10/07/17. - */ - -import org.qtproject.qt5.android.bindings.QtActivity; -import android.content.Intent; -import android.provider.MediaStore; -import android.util.Log; - - -public class RetroshareImagePicker extends QtActivity{ - - public static Intent imagePickerIntent() { - - Log.i("RetroshareImagePicker", "imagePickerIntent()"); - - Intent intent = new Intent( Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI ); - intent.setType("image/*"); - return Intent.createChooser(intent, "Select Image"); - } -} From 5838b13043852ea86ac3a99efe171d387f13e94a Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 11 Jul 2017 17:35:38 +0200 Subject: [PATCH 17/35] Open image camera or gallery selector from main QtActivity --- .../qml_app/RetroShareQmlActivity.java | 70 +++++++++++++++++++ retroshare-qml-app/src/androidimagepicker.h | 7 +- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java index 389ee1448..a14d69f19 100644 --- a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java +++ b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java @@ -19,17 +19,24 @@ package org.retroshare.android.qml_app; import android.app.ActivityManager; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.provider.MediaStore; import android.util.Log; +import android.net.Uri; + import org.qtproject.qt5.android.bindings.QtActivity; import org.retroshare.android.qml_app.jni.NativeCalls; public class RetroShareQmlActivity extends QtActivity { + + static final int PICK_PHOTO = 1; + @Override public void onCreate(Bundle savedInstanceState) { @@ -73,4 +80,67 @@ public class RetroShareQmlActivity extends QtActivity return true; return false; } + + private Uri capturedImageURI; + + public void openImagePicker() + { + Log.i("RetroShareQmlActivity", "openImagePicker()"); + + Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + pickIntent.setType("image/*"); + + ContentValues values = new ContentValues(); + values.put(MediaStore.Images.Media.TITLE, "Retroshare Avatar"); + capturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); + Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + takePicture.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageURI); + + Intent chooserIntent = Intent.createChooser(pickIntent, "Select Image"); + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {takePicture}); + + startActivityForResult( chooserIntent, PICK_PHOTO); + }; + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + + Log.i("RetroShareQmlActivity", "onActivityResult()" + String.valueOf(requestCode)); + + if (resultCode == RESULT_OK) + { + if (requestCode == PICK_PHOTO) + { + final boolean isCamera; + + if (data == null) + { + isCamera = true; + } + else + { + final String action = data.getAction(); + if (action == null) { + isCamera = false; + } else { + isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); + } + } + + Uri selectedImageUri; + if (isCamera) { + selectedImageUri = capturedImageURI; + } else { + selectedImageUri = data == null ? null : data.getData(); + } + + Log.i("RetroShareQmlActivity", "Image uri found!" + selectedImageUri.toString()); + + } + } + } + + + + + } diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index d30026701..d6d3437c1 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -19,10 +19,9 @@ public slots: qDebug() << "Starting image picker intent"; #ifdef __ANDROID__ - QAndroidJniObject::callStaticMethod( - "org/retroshare/android/qml_app/RetroshareImagePicker", - "imagePickerIntent", - "()Landroid/content/Intent;" ); + QtAndroid::androidActivity().callMethod( + "openImagePicker", + "()V" ); #endif // __ANDROID__ } }; From 8a595032600c60e2bcd3d4f3953466669c31a749 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 11 Jul 2017 18:37:01 +0200 Subject: [PATCH 18/35] Send resulting image uri via native calls --- .../qml_app/RetroShareQmlActivity.java | 26 +++++++++++++------ .../src/components/CustomFileChooser.qml | 0 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 retroshare-qml-app/src/components/CustomFileChooser.qml diff --git a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java index a14d69f19..7c1525824 100644 --- a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java +++ b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java @@ -102,8 +102,8 @@ public class RetroShareQmlActivity extends QtActivity startActivityForResult( chooserIntent, PICK_PHOTO); }; - public void onActivityResult(int requestCode, int resultCode, Intent data) { - + public void onActivityResult(int requestCode, int resultCode, Intent data) + { Log.i("RetroShareQmlActivity", "onActivityResult()" + String.valueOf(requestCode)); if (resultCode == RESULT_OK) @@ -119,22 +119,32 @@ public class RetroShareQmlActivity extends QtActivity else { final String action = data.getAction(); - if (action == null) { + if (action == null) + { isCamera = false; - } else { + } + else + { isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); } } Uri selectedImageUri; - if (isCamera) { + if (isCamera) + { selectedImageUri = capturedImageURI; - } else { + } + else + { selectedImageUri = data == null ? null : data.getData(); } - Log.i("RetroShareQmlActivity", "Image uri found!" + selectedImageUri.toString()); - + String uri = selectedImageUri.toString(); + if (uri != null) + { + Log.i("RetroShareQmlActivity", "Image uri found!" + uri); + NativeCalls.notifyIntentUri(uri); + } } } } diff --git a/retroshare-qml-app/src/components/CustomFileChooser.qml b/retroshare-qml-app/src/components/CustomFileChooser.qml new file mode 100644 index 000000000..e69de29bb From c83ce8625284c66e321149e1d44fce36eab42154 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 11 Jul 2017 18:56:38 +0200 Subject: [PATCH 19/35] Create custom filechooser depending on OS type --- retroshare-qml-app/src/ContactDetails.qml | 18 +++++--- .../src/components/CustomFileChooser.qml | 45 +++++++++++++++++++ retroshare-qml-app/src/qml.qrc | 1 + 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/retroshare-qml-app/src/ContactDetails.qml b/retroshare-qml-app/src/ContactDetails.qml index f3d3b6697..fdcdca391 100644 --- a/retroshare-qml-app/src/ContactDetails.qml +++ b/retroshare-qml-app/src/ContactDetails.qml @@ -19,6 +19,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import "." //Needed for ClipboardWrapper singleton +import "./components" import "URI.js" as UriJs Item @@ -28,13 +29,18 @@ Item property bool is_contact: cntDt.md.is_contact Button - { - text: "Open f d " - onClicked: - { - androidImagePicker.openPicker() - } + { + text: "Open f d " + onClicked: + { + fileChooser.open() } + CustomFileChooser + { + id: fileChooser + + } + } ColorHash { diff --git a/retroshare-qml-app/src/components/CustomFileChooser.qml b/retroshare-qml-app/src/components/CustomFileChooser.qml index e69de29bb..5fd75a972 100644 --- a/retroshare-qml-app/src/components/CustomFileChooser.qml +++ b/retroshare-qml-app/src/components/CustomFileChooser.qml @@ -0,0 +1,45 @@ +import QtQuick 2.7 +import QtQuick.Dialogs 1.2 + +Item +{ + id: compRoot + + FileDialog + { + id: fileDialog + title: "Please choose a file" + folder: shortcuts.pictures + nameFilters: [ "Image files (*.png *.jpg)"] + visible: false + onAccepted: { + console.log("You chose: " + fileDialog.fileUrls) + } + onRejected: { + console.log("Canceled") + } + } + + + function open() + { + if (Qt.platform.os === "android") + { + console.log("ImagePicker Android platform detected") + mainWindow.addUriHandler("/media", androidResult) + androidImagePicker.openPicker() + } + else + { + fileDialog.visible = true + } + } + + function androidResult (uri) + { + console.log("Android image uri found" , uri) + + } + + +} diff --git a/retroshare-qml-app/src/qml.qrc b/retroshare-qml-app/src/qml.qrc index 3859fde54..49d05363a 100644 --- a/retroshare-qml-app/src/qml.qrc +++ b/retroshare-qml-app/src/qml.qrc @@ -29,5 +29,6 @@ icons/rating-unrated.png icons/rating.png TimedPopup.qml + components/CustomFileChooser.qml From f6cd3b42adae802d975dc692aed378e8c256734e Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 11 Jul 2017 19:13:55 +0200 Subject: [PATCH 20/35] Refactor handleIntentUri to work also with authorities --- retroshare-qml-app/src/main-app.qml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/main-app.qml b/retroshare-qml-app/src/main-app.qml index 497119d69..28047157f 100644 --- a/retroshare-qml-app/src/main-app.qml +++ b/retroshare-qml-app/src/main-app.qml @@ -239,7 +239,7 @@ ApplicationWindow function handleIntentUri(uriStr) { - console.log("handleIntentUri(uriStr)") + console.log("handleIntentUri(uriStr)", uriStr) if(!Array.isArray(uriStr.match(/:\/\/[a-zA-Z.-]*\//g))) { @@ -257,7 +257,10 @@ ApplicationWindow var uri = new UriJs.URI(uriStr) var hPath = uri.path() // no nesting ATM segmentCoded() - console.log(hPath) + console.log("hPath", hPath) + + var authority = uri.authority() + console.log("authority", authority) if(typeof uriHandlersRegister[hPath] == "function") { @@ -265,6 +268,13 @@ ApplicationWindow hPath, uriHandlersRegister[hPath]) uriHandlersRegister[hPath](uriStr) } + + else if (typeof uriHandlersRegister[authority] == "function" ) + { + console.log("handleIntentUri(uriStr)", "found handler for path", + authority, uriHandlersRegister[authority]) + uriHandlersRegister[authority](uriStr) + } } function certificateLinkHandler(uriStr) From 240469600391b63b32df40d31cc85f4581fe458c Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 11 Jul 2017 19:17:47 +0200 Subject: [PATCH 21/35] Handle signal when file is choosed --- retroshare-qml-app/src/ContactDetails.qml | 4 ++++ retroshare-qml-app/src/components/CustomFileChooser.qml | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/ContactDetails.qml b/retroshare-qml-app/src/ContactDetails.qml index fdcdca391..07c591ee4 100644 --- a/retroshare-qml-app/src/ContactDetails.qml +++ b/retroshare-qml-app/src/ContactDetails.qml @@ -38,6 +38,10 @@ Item CustomFileChooser { id: fileChooser + onResultFileChanged: + { + console.log("Result file changed! " , resultFile) + } } } diff --git a/retroshare-qml-app/src/components/CustomFileChooser.qml b/retroshare-qml-app/src/components/CustomFileChooser.qml index 5fd75a972..299d7d11f 100644 --- a/retroshare-qml-app/src/components/CustomFileChooser.qml +++ b/retroshare-qml-app/src/components/CustomFileChooser.qml @@ -5,6 +5,8 @@ Item { id: compRoot + property var resultFile + FileDialog { id: fileDialog @@ -14,6 +16,7 @@ Item visible: false onAccepted: { console.log("You chose: " + fileDialog.fileUrls) + resultFile = fileDialog.fileUrls } onRejected: { console.log("Canceled") @@ -26,7 +29,7 @@ Item if (Qt.platform.os === "android") { console.log("ImagePicker Android platform detected") - mainWindow.addUriHandler("/media", androidResult) + mainWindow.addUriHandler("media", androidResult) androidImagePicker.openPicker() } else @@ -38,7 +41,8 @@ Item function androidResult (uri) { console.log("Android image uri found" , uri) - + resultFile = uri + mainWindow.delUriHandler("media", androidResult) } From 2d9f062c27400deba48daa566fff51182af3e85b Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 12 Jul 2017 15:37:34 +0200 Subject: [PATCH 22/35] Get real file path from Uri --- .../qml_app/RetroShareQmlActivity.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java index 7c1525824..68862b3f3 100644 --- a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java +++ b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java @@ -22,6 +22,7 @@ import android.app.ActivityManager; import android.content.ContentValues; import android.content.Context; import android.content.Intent; +import android.database.Cursor; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; @@ -139,16 +140,28 @@ public class RetroShareQmlActivity extends QtActivity selectedImageUri = data == null ? null : data.getData(); } - String uri = selectedImageUri.toString(); + String uri = getRealPathFromURI(selectedImageUri); if (uri != null) { - Log.i("RetroShareQmlActivity", "Image uri found!" + uri); - NativeCalls.notifyIntentUri(uri); + Log.i("RetroShareQmlActivity", "Image path from uri found!" + uri); + NativeCalls.notifyIntentUri("//file"+uri); // Add the authority for get it on qml code } } } } + public String getRealPathFromURI(Uri uri) { + String[] projection = { MediaStore.Images.Media.DATA }; + @SuppressWarnings("deprecation") + Cursor cursor = managedQuery(uri, projection, null, null, null); + int column_index = cursor + .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + cursor.moveToFirst(); + String result = cursor.getString(column_index); + cursor.close(); + return result; + } + From 7698e74387aa6266b2a8dd501d8670d5c9800d7a Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 12 Jul 2017 15:43:07 +0200 Subject: [PATCH 23/35] Set correct authority to handle image choosed --- retroshare-qml-app/src/components/CustomFileChooser.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/components/CustomFileChooser.qml b/retroshare-qml-app/src/components/CustomFileChooser.qml index 299d7d11f..fd73d3c5c 100644 --- a/retroshare-qml-app/src/components/CustomFileChooser.qml +++ b/retroshare-qml-app/src/components/CustomFileChooser.qml @@ -29,7 +29,7 @@ Item if (Qt.platform.os === "android") { console.log("ImagePicker Android platform detected") - mainWindow.addUriHandler("media", androidResult) + mainWindow.addUriHandler("file", androidResult) androidImagePicker.openPicker() } else @@ -40,7 +40,7 @@ Item function androidResult (uri) { - console.log("Android image uri found" , uri) + console.log("@@@@@@@@@ Android image uri found" , uri) resultFile = uri mainWindow.delUriHandler("media", androidResult) } From e268fe01459226d4d55ed54dc166cd17e4120722 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 12 Jul 2017 15:43:39 +0200 Subject: [PATCH 24/35] Set avatar picker only on owned identity --- retroshare-qml-app/src/ContactDetails.qml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/retroshare-qml-app/src/ContactDetails.qml b/retroshare-qml-app/src/ContactDetails.qml index 07c591ee4..9ed2fda2b 100644 --- a/retroshare-qml-app/src/ContactDetails.qml +++ b/retroshare-qml-app/src/ContactDetails.qml @@ -27,10 +27,12 @@ Item id: cntDt property var md property bool is_contact: cntDt.md.is_contact + property bool isOwn: cntDt.md.own Button { text: "Open f d " + visible: isOwn onClicked: { fileChooser.open() From 9a621b750971e864b607afc12574b7598c39b836 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 12 Jul 2017 16:20:59 +0200 Subject: [PATCH 25/35] Set filechooser to return a single url --- retroshare-qml-app/src/components/CustomFileChooser.qml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/retroshare-qml-app/src/components/CustomFileChooser.qml b/retroshare-qml-app/src/components/CustomFileChooser.qml index fd73d3c5c..a9dae21de 100644 --- a/retroshare-qml-app/src/components/CustomFileChooser.qml +++ b/retroshare-qml-app/src/components/CustomFileChooser.qml @@ -14,9 +14,10 @@ Item folder: shortcuts.pictures nameFilters: [ "Image files (*.png *.jpg)"] visible: false + selectMultiple: false onAccepted: { - console.log("You chose: " + fileDialog.fileUrls) - resultFile = fileDialog.fileUrls + console.log("You chose: " + fileDialog.fileUrl) + resultFile = fileDialog.fileUrl } onRejected: { console.log("Canceled") @@ -40,7 +41,7 @@ Item function androidResult (uri) { - console.log("@@@@@@@@@ Android image uri found" , uri) + console.log("Android image uri found" , uri) resultFile = uri mainWindow.delUriHandler("media", androidResult) } From e58cd8f363afb0ffdf16b3ca0cc394995ae28c3b Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 12 Jul 2017 16:47:12 +0200 Subject: [PATCH 26/35] Create a funtion to generate filepath from received uri --- .../src/components/CustomFileChooser.qml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/components/CustomFileChooser.qml b/retroshare-qml-app/src/components/CustomFileChooser.qml index a9dae21de..4d054351f 100644 --- a/retroshare-qml-app/src/components/CustomFileChooser.qml +++ b/retroshare-qml-app/src/components/CustomFileChooser.qml @@ -1,6 +1,8 @@ import QtQuick 2.7 import QtQuick.Dialogs 1.2 +import "../URI.js" as UriJs + Item { id: compRoot @@ -41,10 +43,18 @@ Item function androidResult (uri) { - console.log("Android image uri found" , uri) - resultFile = uri + console.log("QML Android image uri found" , uri) + resultFile = uriToFilePath (uri) mainWindow.delUriHandler("media", androidResult) } + function normalizeUriToFilePath (uriStr) + { + var uri = new UriJs.URI(uriStr) + var hPath = uri.path() + return "file:///"+hPath + + } + } From d9662d81e0a1dda82c453403be653483414320ef Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 12 Jul 2017 16:48:26 +0200 Subject: [PATCH 27/35] Create a component to see the choosed image for debugging purpose --- retroshare-qml-app/src/ContactDetails.qml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/retroshare-qml-app/src/ContactDetails.qml b/retroshare-qml-app/src/ContactDetails.qml index 9ed2fda2b..8289b2905 100644 --- a/retroshare-qml-app/src/ContactDetails.qml +++ b/retroshare-qml-app/src/ContactDetails.qml @@ -43,11 +43,21 @@ Item onResultFileChanged: { console.log("Result file changed! " , resultFile) + newAvatar.source = resultFile } } } + Image + { + id: newAvatar + height: colorHash.height + width: colorHash.height + fillMode: Image.PreserveAspectFit + + } + ColorHash { id: colorHash From c570aae9f742b1522d1eeeab515323228e3afaa6 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 18 Jul 2017 16:16:35 +0200 Subject: [PATCH 28/35] Function to convert an image to a png base64 format --- retroshare-qml-app/src/androidimagepicker.h | 44 ++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index d6d3437c1..0b486eb34 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -3,6 +3,12 @@ #include #include +#include +#include +#include +#include +#include + #ifdef __ANDROID__ # include # include @@ -18,10 +24,38 @@ public slots: { qDebug() << "Starting image picker intent"; - #ifdef __ANDROID__ - QtAndroid::androidActivity().callMethod( - "openImagePicker", - "()V" ); - #endif // __ANDROID__ +#ifdef __ANDROID__ + QtAndroid::androidActivity().callMethod( + "openImagePicker", + "()V" ); +#endif // __ANDROID__ + + } + + // Used to convert a given image path into a png base64 string + static QString imageToBase64 (QString const& path) + { + // Get local path from uri + QUrl url (path); + QString localPath = url.toLocalFile(); + + // Read the image + QImageReader reader; + reader.setFileName(localPath); + QImage image = reader.read(); + + // Transform image into PNG format + QByteArray ba; + QBuffer buffer( &ba ); + buffer.open( QIODevice::WriteOnly ); + image.save( &buffer, "PNG" ); + + // Get Based 64 image string + QString encoded = QString(ba.toBase64()); + + qDebug() << "imageToBase64() " ; + + return encoded; + } }; From d64daa7d49b66fda6b4b8a6fe0d65795641afe0e Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 18 Jul 2017 16:25:38 +0200 Subject: [PATCH 29/35] Change avatar via rsapi --- retroshare-qml-app/src/ContactDetails.qml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/retroshare-qml-app/src/ContactDetails.qml b/retroshare-qml-app/src/ContactDetails.qml index 3b0aa4e63..ceed88f29 100644 --- a/retroshare-qml-app/src/ContactDetails.qml +++ b/retroshare-qml-app/src/ContactDetails.qml @@ -44,16 +44,23 @@ Item { console.log("Result file changed! " , resultFile) newAvatar.source = resultFile - } + var base64Image = androidImagePicker.imageToBase64(resultFile) + + rsApi.request("/identity/set_avatar", {"gxs_id": cntDt.md.gxs_id, "avatar": base64Image }, + function (res){ + console.log("Avatar changed! " , JSON.stringify(res)) + } + ) + } } } Image { id: newAvatar - height: colorHash.height - width: colorHash.height + height: topFace.height + width: topFace.height fillMode: Image.PreserveAspectFit } From c0d00c8b7c691e90a897de577bdaf8316b00692b Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 18 Jul 2017 16:36:54 +0200 Subject: [PATCH 30/35] Stringfy correctly the params sent to the api --- retroshare-qml-app/src/ContactDetails.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-qml-app/src/ContactDetails.qml b/retroshare-qml-app/src/ContactDetails.qml index ceed88f29..fff6f9f48 100644 --- a/retroshare-qml-app/src/ContactDetails.qml +++ b/retroshare-qml-app/src/ContactDetails.qml @@ -47,7 +47,7 @@ Item var base64Image = androidImagePicker.imageToBase64(resultFile) - rsApi.request("/identity/set_avatar", {"gxs_id": cntDt.md.gxs_id, "avatar": base64Image }, + rsApi.request("/identity/set_avatar", JSON.stringify({"gxs_id": cntDt.md.gxs_id, "avatar": base64Image }), function (res){ console.log("Avatar changed! " , JSON.stringify(res)) } From 938c3109f6ff38d5bd3f693d91d6c2fff5d93ccc Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 18 Jul 2017 17:05:04 +0200 Subject: [PATCH 31/35] Solve incorrect behaviours on android --- .../org/retroshare/android/qml_app/RetroShareQmlActivity.java | 1 - retroshare-qml-app/src/components/CustomFileChooser.qml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java index d61b524d1..365778142 100644 --- a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java +++ b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java @@ -169,7 +169,6 @@ public class RetroShareQmlActivity extends QtActivity .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String result = cursor.getString(column_index); - cursor.close(); return result; } diff --git a/retroshare-qml-app/src/components/CustomFileChooser.qml b/retroshare-qml-app/src/components/CustomFileChooser.qml index 4d054351f..e7451dee5 100644 --- a/retroshare-qml-app/src/components/CustomFileChooser.qml +++ b/retroshare-qml-app/src/components/CustomFileChooser.qml @@ -44,7 +44,7 @@ Item function androidResult (uri) { console.log("QML Android image uri found" , uri) - resultFile = uriToFilePath (uri) + resultFile = normalizeUriToFilePath (uri) mainWindow.delUriHandler("media", androidResult) } From 875b625abb7ef86e21dcf34069e39591b8a7c91e Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 18 Jul 2017 18:09:35 +0200 Subject: [PATCH 32/35] Scale image before base64 encoding --- retroshare-qml-app/src/androidimagepicker.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index 0b486eb34..b30c6c18c 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -9,6 +9,7 @@ #include #include + #ifdef __ANDROID__ # include # include @@ -39,21 +40,25 @@ public slots: QUrl url (path); QString localPath = url.toLocalFile(); + qDebug() << "imageToBase64() local path:" << localPath ; + // Read the image QImageReader reader; reader.setFileName(localPath); QImage image = reader.read(); + image = image.scaled(96,96,Qt::KeepAspectRatio,Qt::SmoothTransformation); + // Transform image into PNG format QByteArray ba; QBuffer buffer( &ba ); buffer.open( QIODevice::WriteOnly ); - image.save( &buffer, "PNG" ); + image.save( &buffer, "png" ); // Get Based 64 image string QString encoded = QString(ba.toBase64()); - qDebug() << "imageToBase64() " ; + qDebug() << "imageToBase64() " << encoded ; return encoded; From 3fecbe02a34f6f2142d3a6a704d915ea8bc01654 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 18 Jul 2017 18:16:51 +0200 Subject: [PATCH 33/35] Set avatar button on proper position --- retroshare-qml-app/src/ContactDetails.qml | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/retroshare-qml-app/src/ContactDetails.qml b/retroshare-qml-app/src/ContactDetails.qml index fff6f9f48..aa3dec058 100644 --- a/retroshare-qml-app/src/ContactDetails.qml +++ b/retroshare-qml-app/src/ContactDetails.qml @@ -31,8 +31,14 @@ Item Button { - text: "Open f d " + id: avatarPicker + + text: "Change your Avatar" visible: isOwn + + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + onClicked: { fileChooser.open() @@ -43,27 +49,17 @@ Item onResultFileChanged: { console.log("Result file changed! " , resultFile) - newAvatar.source = resultFile var base64Image = androidImagePicker.imageToBase64(resultFile) rsApi.request("/identity/set_avatar", JSON.stringify({"gxs_id": cntDt.md.gxs_id, "avatar": base64Image }), function (res){ console.log("Avatar changed! " , JSON.stringify(res)) - } - ) + }) } } } - Image - { - id: newAvatar - height: topFace.height - width: topFace.height - fillMode: Image.PreserveAspectFit - - } AvatarOrColorHash { @@ -71,7 +67,7 @@ Item gxs_id: cntDt.md.gxs_id - anchors.top: parent.top + anchors.top: (isOwn)? avatarPicker.bottom : parent.top anchors.topMargin: 6 anchors.horizontalCenter: parent.horizontalCenter } From c880f5f783759f9bbcb6f19182958fc3d5e9f49a Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 18 Jul 2017 19:26:31 +0200 Subject: [PATCH 34/35] Reload top face when avatar is changed --- retroshare-qml-app/src/ContactDetails.qml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/retroshare-qml-app/src/ContactDetails.qml b/retroshare-qml-app/src/ContactDetails.qml index aa3dec058..fdb6ca771 100644 --- a/retroshare-qml-app/src/ContactDetails.qml +++ b/retroshare-qml-app/src/ContactDetails.qml @@ -53,9 +53,15 @@ Item var base64Image = androidImagePicker.imageToBase64(resultFile) rsApi.request("/identity/set_avatar", JSON.stringify({"gxs_id": cntDt.md.gxs_id, "avatar": base64Image }), - function (res){ - console.log("Avatar changed! " , JSON.stringify(res)) - }) + function (par) + { + var jP = JSON.parse(par.response) + if (jP.returncode === "ok") + { + console.log("Avatar changed! ") + topFace.getDetails() + } + }) } } } From 25d27b0f7f248596307b69478bc3621c82be38e9 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Tue, 18 Jul 2017 19:27:56 +0200 Subject: [PATCH 35/35] Disable base64 string debug --- retroshare-qml-app/src/androidimagepicker.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index b30c6c18c..ad5f0e302 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -58,7 +58,7 @@ public slots: // Get Based 64 image string QString encoded = QString(ba.toBase64()); - qDebug() << "imageToBase64() " << encoded ; + qDebug() << "imageToBase64() encoded" ; return encoded;