Advertisement
Guest User

Work with taskbar

a guest
Jul 16th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.90 KB | None | 0 0
  1. diff --git a/src/mainwin.cpp b/src/mainwin.cpp
  2. index 3bbd663b..b45ffce7 100644
  3. --- a/src/mainwin.cpp
  4. +++ b/src/mainwin.cpp
  5. @@ -71,6 +71,8 @@
  6.  #include <QtAlgorithms>
  7.  #ifdef Q_OS_WIN
  8.  #include <windows.h>
  9. +#include "widgets/thumbnailtoolbar.h"
  10. +#include <QWinTaskbarButton>
  11.  #endif
  12.  #ifdef HAVE_X11
  13.  #include <x11windowsystem.h>
  14. @@ -154,6 +156,8 @@ public:
  15.  
  16.  #ifdef Q_OS_WIN
  17.      DWORD deactivationTickCount;
  18. +    QPointer<QWinTaskbarButton> taskbarBtn_;
  19. +    QPointer<PsiThumbnailToolBar> thumbnailToolBar_;
  20.  #endif
  21.  
  22.      void        registerActions();
  23. @@ -510,16 +514,9 @@ MainWin::MainWin(bool _onTop, bool _asTool, PsiCon *psi) :
  24.  
  25.      buildToolbars();
  26.      // setUnifiedTitleAndToolBarOnMac(true);
  27. +
  28.  #ifdef Q_OS_WIN
  29. -    thumbnailToolBar_ = new PsiThumbnailToolBar(this, windowHandle());
  30. -    connect(thumbnailToolBar_, &PsiThumbnailToolBar::openOptions, this, &MainWin::doOptions);
  31. -    connect(thumbnailToolBar_, &PsiThumbnailToolBar::setOnline, this,
  32. -            [this]() { d->getAction("status_online")->trigger(); });
  33. -    connect(thumbnailToolBar_, &PsiThumbnailToolBar::setOffline, this,
  34. -            [this]() { d->getAction("status_offline")->trigger(); });
  35. -    connect(thumbnailToolBar_, &PsiThumbnailToolBar::runActiveEvent, this, &MainWin::doRecvNextEvent);
  36. -    connect(psi->contactList(), &PsiContactList::queueChanged, this,
  37. -            [this]() { thumbnailToolBar_->updateToolBar(d->nextAmount > 0); });
  38. +    updateWinTaskbar(_asTool);
  39.  #endif
  40.  
  41.      connect(qApp, SIGNAL(dockActivated()), SLOT(dockActivated()));
  42. @@ -752,6 +749,9 @@ void MainWin::setWindowOpts(bool _onTop, bool _asTool)
  43.  
  44.      setWindowFlags(flags);
  45.      show();
  46. +#ifdef Q_OS_WIN
  47. +    updateWinTaskbar(_asTool);
  48. +#endif
  49.  }
  50.  
  51.  void MainWin::setUseDock(bool use)
  52. @@ -1478,6 +1478,35 @@ bool MainWin::nativeEvent(const QByteArray &eventType, MSG *msg, long *result)
  53.      }
  54.      return false;
  55.  }
  56. +
  57. +void MainWin::updateWinTaskbar(bool enabled)
  58. +{
  59. +    if(! enabled) {
  60. +        if(!d->thumbnailToolBar_) {
  61. +            d->thumbnailToolBar_ = new PsiThumbnailToolBar(this, windowHandle());
  62. +            connect(d->thumbnailToolBar_, &PsiThumbnailToolBar::openOptions, this, &MainWin::doOptions);
  63. +            connect(d->thumbnailToolBar_, &PsiThumbnailToolBar::setOnline, this,
  64. +                    [this]() { d->getAction("status_online")->trigger(); });
  65. +            connect(d->thumbnailToolBar_, &PsiThumbnailToolBar::setOffline, this,
  66. +                    [this]() { d->getAction("status_offline")->trigger(); });
  67. +            connect(d->thumbnailToolBar_, &PsiThumbnailToolBar::runActiveEvent, this, &MainWin::doRecvNextEvent);
  68. +            connect(d->psi->contactList(), &PsiContactList::queueChanged, this,
  69. +                    [this]() { d->thumbnailToolBar_->updateToolBar(d->nextAmount > 0); });
  70. +        }
  71. +        if(!d->taskbarBtn_)
  72. +            d->taskbarBtn_ = new QWinTaskbarButton(this);
  73. +    }
  74. +    else {
  75. +        if(d->thumbnailToolBar_) {
  76. +            delete d->thumbnailToolBar_;
  77. +            d->thumbnailToolBar_ = nullptr;
  78. +        }
  79. +        if(d->taskbarBtn_) {
  80. +            delete d->taskbarBtn_;
  81. +            d->taskbarBtn_ = nullptr;
  82. +        }
  83. +    }
  84. +}
  85.  #endif
  86.  
  87.  void MainWin::updateCaption()
  88. diff --git a/src/mainwin.h b/src/mainwin.h
  89. index 02f38fde..802f064e 100644
  90. --- a/src/mainwin.h
  91. +++ b/src/mainwin.h
  92. @@ -22,9 +22,6 @@
  93.  
  94.  #include "advwidget.h"
  95.  #include "xmpp_status.h"
  96. -#ifdef Q_OS_WIN
  97. -#include "widgets/thumbnailtoolbar.h"
  98. -#endif
  99.  
  100.  #include <QList>
  101.  #include <QMainWindow>
  102. @@ -188,14 +185,15 @@ private:
  103.  
  104.      void buildStatusMenu(GlobalStatusMenu *statusMenu);
  105.  
  106. +#ifdef Q_OS_WIN
  107. +    void updateWinTaskbar(bool enabled);
  108. +#endif
  109. +
  110.  private:
  111.      class Private;
  112.      Private *d;
  113.      friend class Private;
  114.      QList<PsiToolBar *> toolbars_;
  115. -#ifdef Q_OS_WIN
  116. -    PsiThumbnailToolBar *thumbnailToolBar_;
  117. -#endif
  118.  };
  119.  
  120.  #endif // MAINWIN_H
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement