Advertisement
Guest User

Psi+ pins+filesharing patch

a guest
Jun 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.11 KB | None | 0 0
  1. diff --git a/src/filesharingmanager.cpp b/src/filesharingmanager.cpp
  2. index 508e75af..1f5a6653 100644
  3. --- a/src/filesharingmanager.cpp
  4. +++ b/src/filesharingmanager.cpp
  5. @@ -300,3 +300,14 @@ QList<FileSharingItem*> FileSharingManager::fromMimeData(const QMimeData *data,
  6.      return ret;
  7.  }
  8.  
  9. +QList<FileSharingItem*> FileSharingManager::fromFilesList(const QStringList &fileList, PsiAccount *acc)
  10. +{
  11. +    QList<FileSharingItem*> ret;
  12. +    if(fileList.isEmpty())
  13. +        return ret;
  14. +    foreach (const QString &file, fileList) {
  15. +        auto item = new FileSharingItem(file, acc, this);
  16. +        ret << item;
  17. +    }
  18. +    return ret;
  19. +}
  20. diff --git a/src/filesharingmanager.h b/src/filesharingmanager.h
  21. index c8880e5f..00000857 100644
  22. --- a/src/filesharingmanager.h
  23. +++ b/src/filesharingmanager.h
  24. @@ -84,6 +84,7 @@ public:
  25.      FileCacheItem *getCacheItem(const QString &id, bool reborn = false);
  26.      FileCacheItem *saveToCache(const QString &id, const QByteArray &data, const QVariantMap &metadata, unsigned int maxAge);
  27.      QList<FileSharingItem *> fromMimeData(const QMimeData *data, PsiAccount *acc);
  28. +    QList<FileSharingItem *> fromFilesList(const QStringList &fileList, PsiAccount *acc);
  29.  signals:
  30.  
  31.  public slots:
  32. diff --git a/src/groupchatdlg.cpp b/src/groupchatdlg.cpp
  33. index 53d9da5c..b1c63533 100644
  34. --- a/src/groupchatdlg.cpp
  35. +++ b/src/groupchatdlg.cpp
  36. @@ -97,6 +97,7 @@
  37.  #include "filesharedlg.h"
  38.  #include "filesharingmanager.h"
  39.  #include "tabdlg.h"
  40. +#include "fileutil.h"
  41.  
  42.  #ifdef Q_OS_WIN
  43.  #include <windows.h>
  44. @@ -925,9 +926,37 @@ GCMainDlg::GCMainDlg(PsiAccount *pa, const Jid &j, TabManager *tabManager)
  45.          else if (name == QLatin1String("gchat_templates")) {
  46.              action->setMenu(getTemplateMenu());
  47.          }
  48. -        else if (name == "gchat_pin_tab" || name == "gchat_unpin_tab") {
  49. +        else if (name == "gchat_share_files") {
  50. +            connect(action, &QAction::triggered, this, [this](){
  51. +                QStringList files = FileUtil::getOpenFileNames(this, tr("Open Files For Sharing"));
  52. +                if(files.isEmpty())
  53. +                    return;
  54. +
  55. +                FileSharingManager *fManager = new FileSharingManager(this);
  56. +                auto itList = fManager->fromFilesList(files, account());
  57. +                auto dlg = new FileShareDlg(itList, this);
  58. +
  59. +                connect(dlg, &FileShareDlg::published, this, [this, dlg](){
  60. +                    FileSharingItem *item;
  61. +                    while ((item = dlg->takePendingPublisher())) {
  62. +                        Message m(jid());
  63. +                        m.setType("groupchat");
  64. +                        if (item->setupMessage(m)) {
  65. +                            aSend(m);
  66. +                        }
  67. +                    }
  68. +                });
  69. +
  70. +                dlg->show();
  71. +
  72. +            });
  73. +        }
  74. +        else if (name == "gchat_pin_tab") {
  75.              connect(action, SIGNAL(triggered()), SLOT(pinTab()));
  76.          }
  77. +        else if (name == "gchat_unpin_tab") {
  78. +            connect(action, SIGNAL(triggered()), SLOT(unpinTab()));
  79. +        }
  80.      }
  81.  
  82.      actList = account()->psi()->actionList()->actionLists(PsiActionList::Actions_Common).at(0);
  83. diff --git a/src/psiactionlist.cpp b/src/psiactionlist.cpp
  84. index 106e7eea..f801e13d 100644
  85. --- a/src/psiactionlist.cpp
  86. +++ b/src/psiactionlist.cpp
  87. @@ -456,6 +456,7 @@ void PsiActionList::Private::createChat()
  88.          IconAction *actTemplates = new IconAction(tr("Templates"), "psi/action_templates", tr("Templates"), 0, this);
  89.          IconAction *actPinTab = new IconAction(tr("Pin Tab"), "psi/pin", tr("Pin Tab"), 0 , this);
  90.          IconAction *actUnpinTab = new IconAction(tr("Unpin Tab"), "psi/pin", tr("Unpin Tab"), 0 , this);
  91. +        IconAction *actShareFiles = new IconAction(tr("Share Files"), "psi/filemanager", tr("Share Files"), 0, this);
  92.  
  93.          ActionNames actions[] = {
  94.              { "chat_clear",  actClear  },
  95. @@ -471,6 +472,7 @@ void PsiActionList::Private::createChat()
  96.              { "chat_compact", actCompact   },
  97.              { "chat_active_contacts", actActiveContacts   },
  98.              { "chat_templates", actTemplates },
  99. +            { "chat_share_files", actShareFiles},
  100.              { "chat_pin_tab", actPinTab },
  101.              { "chat_unpin_tab", actUnpinTab },
  102.              { "", nullptr }
  103. @@ -493,6 +495,7 @@ void PsiActionList::Private::createGroupchat()
  104.          IconAction *actTemplates = new IconAction(tr("Templates"), "psi/action_templates", tr("Templates"), 0, this);
  105.          IconAction *actPinTab = new IconAction(tr("Pin Tab"), "psi/pin", tr("Pin Tab"), 0 , this);
  106.          IconAction *actUnpinTab = new IconAction(tr("Unpin Tab"), "psi/pin", tr("Unpin Tab"), 0 , this);
  107. +        IconAction *actShareFiles = new IconAction(tr("Share Files"), "psi/filemanager", tr("Share Files"), 0, this);
  108.  
  109.          ActionNames actions[] = {
  110.              { "gchat_clear",     actClear     },
  111. @@ -501,6 +504,7 @@ void PsiActionList::Private::createGroupchat()
  112.              { "gchat_configure", actConfigure },
  113.              { "gchat_icon",      actIcon      },
  114.              { "gchat_templates", actTemplates },
  115. +            { "gchat_share_files", actShareFiles},
  116.              { "gchat_pin_tab",   actPinTab    },
  117.              { "gchat_unpin_tab", actUnpinTab  },
  118.              { "", nullptr }
  119. diff --git a/src/psichatdlg.cpp b/src/psichatdlg.cpp
  120. index e7a40ed4..33a2613c 100644
  121. --- a/src/psichatdlg.cpp
  122. +++ b/src/psichatdlg.cpp
  123. @@ -50,8 +50,10 @@
  124.  #include "actionlist.h"
  125.  #include "psiactionlist.h"
  126.  #include "tabdlg.h"
  127. -#ifdef PSI_PLUGINS
  128. +#include "fileutil.h"
  129.  #include "filesharedlg.h"
  130. +#include "filesharingmanager.h"
  131. +#ifdef PSI_PLUGINS
  132.  #include "pluginmanager.h"
  133.  #endif
  134.  
  135. @@ -549,9 +551,37 @@ void PsiChatDlg::initToolButtons()
  136.          else if (name == "chat_templates") {
  137.              action->setMenu(getTemplateMenu());
  138.          }
  139. -        else if (name == "chat_pin_tab" || name == "chat_unpin_tab") {
  140. +        else if (name == "chat_share_files") {
  141. +            connect(action, &QAction::triggered, this, [this](){
  142. +                QStringList files = FileUtil::getOpenFileNames(this, tr("Open Files For Sharing"));
  143. +                if(files.isEmpty())
  144. +                    return;
  145. +
  146. +                FileSharingManager *fManager = new FileSharingManager(this);
  147. +                auto itList = fManager->fromFilesList(files, account());
  148. +                auto dlg = new FileShareDlg(itList, this);
  149. +
  150. +                connect(dlg, &FileShareDlg::published, this, [this, dlg](){
  151. +                    FileSharingItem *item;
  152. +                    while ((item = dlg->takePendingPublisher())) {
  153. +                        Message m(jid());
  154. +                        m.setType("chat");
  155. +                        if (item->setupMessage(m)) {
  156. +                            aSend(m);
  157. +                        }
  158. +                    }
  159. +                });
  160. +
  161. +                dlg->show();
  162. +
  163. +            });
  164. +        }
  165. +        else if (name == "chat_pin_tab") {
  166.              connect(action, SIGNAL(triggered()), SLOT(pinTab()));
  167.          }
  168. +        else if (name == "chat_unpin_tab") {
  169. +            connect(action, SIGNAL(triggered()), SLOT(unpinTab()));
  170. +        }
  171.      }
  172.  
  173.      list = account()->psi()->actionList()->actionLists(PsiActionList::Actions_Common).at(0);
  174. diff --git a/src/tabs/tabbablewidget.cpp b/src/tabs/tabbablewidget.cpp
  175. index 34f16422..4a0bfc90 100644
  176. --- a/src/tabs/tabbablewidget.cpp
  177. +++ b/src/tabs/tabbablewidget.cpp
  178. @@ -42,7 +42,7 @@ TabbableWidget::TabbableWidget(const Jid &jid, PsiAccount *pa, TabManager *tabMa
  179.      , tabManager_(tabManager)
  180.  {
  181.      if (TabbableWidget::chatsCount == 0) {
  182. -        TabbableWidget::templateMenu = new SendButtonTemplatesMenu(NULL);
  183. +        TabbableWidget::templateMenu = new SendButtonTemplatesMenu(nullptr);
  184.          TabbableWidget::templateMenu->setParams(false);
  185.          TabbableWidget::templateMenu->setStyleSheet(PsiOptions::instance()->getOption("options.ui.chat.css").toString());
  186.      }
  187. @@ -124,20 +124,20 @@ TabbableWidget::~TabbableWidget()
  188.      }
  189.      --TabbableWidget::chatsCount;
  190.      if (TabbableWidget::chatsCount == 0) {
  191. -        if (TabbableWidget::templateMenu != NULL) {
  192. +        if (TabbableWidget::templateMenu != nullptr) {
  193.              delete TabbableWidget::templateMenu;
  194. -            TabbableWidget::templateMenu = NULL;
  195. +            TabbableWidget::templateMenu = nullptr;
  196.          }
  197.          if (!TabbableWidget::templateEditDlg.isNull()) {
  198.              delete (TabbableWidget::templateEditDlg);
  199. -            TabbableWidget::templateEditDlg = NULL;
  200. +            TabbableWidget::templateEditDlg = nullptr;
  201.          }
  202.      }
  203.  }
  204.  
  205.  int TabbableWidget::chatsCount = 0;
  206. -SendButtonTemplatesMenu *TabbableWidget::templateMenu = NULL;
  207. -QPointer<SendButtonTemplatesEditor> TabbableWidget::templateEditDlg = NULL;
  208. +SendButtonTemplatesMenu *TabbableWidget::templateMenu = nullptr;
  209. +QPointer<SendButtonTemplatesEditor> TabbableWidget::templateEditDlg = nullptr;
  210.  
  211.  SendButtonTemplatesMenu* TabbableWidget::getTemplateMenu()
  212.  {
  213. @@ -298,3 +298,8 @@ void TabbableWidget::pinTab()
  214.  {
  215.      getManagingTabDlg()->pinTab(this);
  216.  }
  217. +
  218. +void TabbableWidget::unpinTab()
  219. +{
  220. +    getManagingTabDlg()->unpinTab(this);
  221. +}
  222. diff --git a/src/tabs/tabbablewidget.h b/src/tabs/tabbablewidget.h
  223. index a2084748..2f82e237 100644
  224. --- a/src/tabs/tabbablewidget.h
  225. +++ b/src/tabs/tabbablewidget.h
  226. @@ -88,6 +88,7 @@ public slots:
  227.      virtual void ensureTabbedCorrectly();
  228.      void hideTab();
  229.      void pinTab();
  230. +    void unpinTab();
  231.  
  232.  protected:
  233.      virtual void setJid(const Jid&);
  234. diff --git a/src/tabs/tabdlg.cpp b/src/tabs/tabdlg.cpp
  235. index c76e7cde..a6a2075b 100644
  236. --- a/src/tabs/tabdlg.cpp
  237. +++ b/src/tabs/tabdlg.cpp
  238. @@ -273,9 +273,14 @@ void TabDlg::showTabMenu(int tab, QPoint pos, QContextMenuEvent * event)
  239.              tabMenu_->addMenu(sendTo);
  240.          }
  241.  
  242. -        QAction *p = 0;
  243. +        QAction *p = nullptr, *up = nullptr;
  244.          if (PsiOptions::instance()->getOption("options.ui.tabs.multi-rows", true).toBool()) {
  245. -            p = tabMenu_->addAction(tabWidget_->isPagePinned(getTab(tab)) ? tr("Unpin Tab") : tr("Pin Tab"));
  246. +            if (tabWidget_->isPagePinned(getTab(tab))) {
  247. +                up = tabMenu_->addAction(tr("Unpin Tab"));
  248. +            }
  249. +            else{
  250. +                p = tabMenu_->addAction(tr("Pin Tab"));
  251. +            }
  252.          }
  253.  
  254.          QAction *act = tabMenu_->exec(pos);
  255. @@ -293,6 +298,9 @@ void TabDlg::showTabMenu(int tab, QPoint pos, QContextMenuEvent * event)
  256.          else if (p && act == p) {
  257.              pinTab(getTab(tab));
  258.          }
  259. +        else if (up && act == up) {
  260. +            unpinTab(getTab(tab));
  261. +        }
  262.          else {
  263.              TabDlg* target = sentTos[act];
  264.              if (target)
  265. @@ -385,7 +393,7 @@ void TabDlg::setLooks()
  266.  void TabDlg::tabSelected(QWidget* _selected)
  267.  {
  268.      // _selected could be null when TabDlg is closing and deleting all its tabs
  269. -    TabbableWidget* selected = _selected ? qobject_cast<TabbableWidget*>(_selected) : 0;
  270. +    TabbableWidget* selected = _selected ? qobject_cast<TabbableWidget*>(_selected) : nullptr;
  271.      if (!selectedTab_.isNull()) {
  272.          QCoreApplication::postEvent(selectedTab_, new QEvent(QEvent::ActivationChange));
  273.      }
  274. @@ -440,9 +448,19 @@ void TabDlg::hideTab(TabbableWidget* tab)
  275.  
  276.  void TabDlg::pinTab(TabbableWidget* tab)
  277.  {
  278. -    tabWidget_->setPagePinned(tab, !tabWidget_->isPagePinned(tab));
  279. +    if(!tabWidget_->isPagePinned(tab)) {
  280. +        tabWidget_->setPagePinned(tab, true);
  281. +    }
  282.  }
  283.  
  284. +void TabDlg::unpinTab(TabbableWidget* tab)
  285. +{
  286. +    if(tabWidget_->isPagePinned(tab)) {
  287. +        tabWidget_->setPagePinned(tab, false);
  288. +    }
  289. +}
  290. +
  291. +
  292.  void TabDlg::hideAllTab()
  293.  {
  294.      foreach(TabbableWidget* tab, tabs_)
  295. diff --git a/src/tabs/tabdlg.h b/src/tabs/tabdlg.h
  296. index 3652d82b..a861bf39 100644
  297. --- a/src/tabs/tabdlg.h
  298. +++ b/src/tabs/tabdlg.h
  299. @@ -126,6 +126,7 @@ public slots:
  300.      void tabCloseRequested(int i);
  301.      void hideTab(TabbableWidget*);
  302.      void pinTab(TabbableWidget *tab);
  303. +    void unpinTab(TabbableWidget *tab);
  304.      void hideCurrentTab();
  305.      void hideAllTab();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement