Changeset 90556 in vbox
- Timestamp:
- Aug 6, 2021 4:08:18 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 146162
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObject.cpp
r90387 r90556 17 17 18 18 /* GUI includes: */ 19 #include "UIDownloader.h" 19 20 #include "UINotificationObject.h" 20 21 #include "UINotificationProgressTask.h" … … 78 79 connect(m_pTask, &UIProgressTask::sigProgressFinished, 79 80 this, &UINotificationProgress::sltHandleProgressFinished); 81 82 /* And start it finally: */ 83 m_pTask->start(); 80 84 } 81 82 /* And start it finally: */83 m_pTask->start();84 85 } 85 86 … … 104 105 emit sigProgressFinished(); 105 106 } 107 108 109 /********************************************************************************************************************************* 110 * Class UINotificationDownloader implementation. * 111 *********************************************************************************************************************************/ 112 113 UINotificationDownloader::UINotificationDownloader() 114 { 115 } 116 117 UINotificationDownloader::~UINotificationDownloader() 118 { 119 delete m_pDownloader; 120 } 121 122 ulong UINotificationDownloader::percent() const 123 { 124 return m_uPercent; 125 } 126 127 QString UINotificationDownloader::error() const 128 { 129 return m_strError; 130 } 131 132 void UINotificationDownloader::handle() 133 { 134 /* Prepare downloader: */ 135 m_pDownloader = createDownloader(); 136 if (m_pDownloader) 137 { 138 connect(m_pDownloader, &UIDownloader::sigToStartAcknowledging, 139 this, &UINotificationDownloader::sigProgressStarted); 140 connect(m_pDownloader, &UIDownloader::sigToStartDownloading, 141 this, &UINotificationDownloader::sigProgressStarted); 142 connect(m_pDownloader, &UIDownloader::sigToStartVerifying, 143 this, &UINotificationDownloader::sigProgressStarted); 144 connect(m_pDownloader, &UIDownloader::sigProgressChange, 145 this, &UINotificationDownloader::sltHandleProgressChange); 146 connect(m_pDownloader, &UIDownloader::sigProgressFailed, 147 this, &UINotificationDownloader::sltHandleProgressFailed); 148 connect(m_pDownloader, &UIDownloader::sigProgressCanceled, 149 this, &UINotificationDownloader::sigProgressCanceled); 150 connect(m_pDownloader, &UIDownloader::sigProgressFinished, 151 this, &UINotificationDownloader::sigProgressFinished); 152 connect(m_pDownloader, &UIDownloader::destroyed, 153 this, &UINotificationDownloader::sigDownloaderDestroyed); 154 155 /* And start it finally: */ 156 m_pDownloader->start(); 157 } 158 } 159 160 void UINotificationDownloader::close() 161 { 162 /* Cancel downloader: */ 163 if (m_pDownloader) 164 m_pDownloader->cancel(); 165 /* Call to base-class: */ 166 UINotificationObject::close(); 167 } 168 169 void UINotificationDownloader::sltHandleProgressChange(ulong uPercent) 170 { 171 m_uPercent = uPercent; 172 emit sigProgressChange(uPercent); 173 } 174 175 void UINotificationDownloader::sltHandleProgressFailed(const QString &strError) 176 { 177 m_strError = strError; 178 emit sigProgressFailed(); 179 } -
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObject.h
r90290 r90556 24 24 /* Qt includes: */ 25 25 #include <QObject> 26 #include <QPointer> 26 27 27 28 /* GUI includes: */ … … 32 33 33 34 /* Forward declarations: */ 35 class UIDownloader; 34 36 class UINotificationProgressTask; 35 37 … … 119 121 }; 120 122 123 /** UINotificationObject extension for notification-downloader. */ 124 class SHARED_LIBRARY_STUFF UINotificationDownloader : public UINotificationObject 125 { 126 Q_OBJECT; 127 128 signals: 129 130 /** Notifies listeners about progress started. */ 131 void sigProgressStarted(); 132 /** Notifies listeners about progress changed. 133 * @param uPercent Brings new progress percentage value. */ 134 void sigProgressChange(ulong uPercent); 135 /** Notifies listeners about progress failed. */ 136 void sigProgressFailed(); 137 /** Notifies listeners about progress canceled. */ 138 void sigProgressCanceled(); 139 /** Notifies listeners about progress finished. */ 140 void sigProgressFinished(); 141 142 /** Notifies listeners about downloader destroyed. */ 143 void sigDownloaderDestroyed(); 144 145 public: 146 147 /** Constructs notification-downloader. */ 148 UINotificationDownloader(); 149 /** Destructs notification-downloader. */ 150 virtual ~UINotificationDownloader() /* override final */; 151 152 /** Creates and returns started downloader-wrapper. */ 153 virtual UIDownloader *createDownloader() = 0; 154 155 /** Returns current progress percentage value. */ 156 ulong percent() const; 157 /** Returns error-message if any. */ 158 QString error() const; 159 160 /** Handles notification-object being added. */ 161 virtual void handle() /* override final */; 162 163 public slots: 164 165 /** Stops the downloader and notifies model about closing. */ 166 virtual void close() /* override final */; 167 168 private slots: 169 170 /** Handles signal about progress changed. 171 * @param uPercent Brings new progress percentage value. */ 172 void sltHandleProgressChange(ulong uPercent); 173 /** Handles signal about progress failed. 174 * @param strError Brings error message if any. */ 175 void sltHandleProgressFailed(const QString &strError); 176 177 private: 178 179 /** Holds the instance of downloader being wrapped by this notification-downloader. */ 180 QPointer<UIDownloader> m_pDownloader; 181 182 /** Holds the last cached progress percentage value. */ 183 ulong m_uPercent; 184 /** Holds the error message is any. */ 185 QString m_strError; 186 }; 187 121 188 #endif /* !FEQT_INCLUDED_SRC_notificationcenter_UINotificationObject_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjectItem.cpp
r90391 r90556 273 273 274 274 /********************************************************************************************************************************* 275 * Class UINotificationDownloaderItem implementation. * 276 *********************************************************************************************************************************/ 277 278 UINotificationDownloaderItem::UINotificationDownloaderItem(QWidget *pParent, UINotificationDownloader *pDownloader /* = 0 */) 279 : UINotificationObjectItem(pParent, pDownloader) 280 , m_pProgressBar(0) 281 { 282 /* Main layout was prepared in base-class: */ 283 if (m_pLayoutMain) 284 { 285 /* Name label was prepared in base-class: */ 286 if (m_pLabelName) 287 m_pLabelName->setText(downloader()->name()); 288 /* Details label was prepared in base-class: */ 289 if (m_pLabelDetails) 290 { 291 int iHint = m_pLabelName->minimumSizeHint().width() 292 + m_pLayoutUpper->spacing() 293 + m_pButtonClose->minimumSizeHint().width(); 294 m_pLabelDetails->setMinimumTextWidth(iHint); 295 updateDetails(); 296 } 297 298 /* Prepare progress-bar: */ 299 m_pProgressBar = new QProgressBar(this); 300 if (m_pProgressBar) 301 { 302 m_pProgressBar->setMinimum(0); 303 m_pProgressBar->setMaximum(100); 304 m_pProgressBar->setValue(downloader()->percent()); 305 306 m_pLayoutMain->addWidget(m_pProgressBar); 307 } 308 } 309 310 /* Prepare downloader connections: */ 311 connect(downloader(), &UINotificationDownloader::sigProgressStarted, 312 this, &UINotificationDownloaderItem::sltHandleProgressStarted); 313 connect(downloader(), &UINotificationDownloader::sigProgressChange, 314 this, &UINotificationDownloaderItem::sltHandleProgressChange); 315 connect(downloader(), &UINotificationDownloader::sigProgressFailed, 316 this, &UINotificationDownloaderItem::sltHandleProgressFinished); 317 connect(downloader(), &UINotificationDownloader::sigProgressCanceled, 318 this, &UINotificationDownloaderItem::sltHandleProgressFinished); 319 connect(downloader(), &UINotificationDownloader::sigProgressFinished, 320 this, &UINotificationDownloaderItem::sltHandleProgressFinished); 321 } 322 323 void UINotificationDownloaderItem::sltHandleProgressStarted() 324 { 325 /* Init progress-bar state: */ 326 if (m_pProgressBar) 327 m_pProgressBar->setValue(0); 328 /* Update details with fetched stuff if any: */ 329 if (m_pLabelDetails) 330 updateDetails(); 331 } 332 333 void UINotificationDownloaderItem::sltHandleProgressChange(ulong uPercent) 334 { 335 /* Update progress-bar state: */ 336 if (m_pProgressBar) 337 m_pProgressBar->setValue(uPercent); 338 } 339 340 void UINotificationDownloaderItem::sltHandleProgressFinished() 341 { 342 /* Finalize progress-bar state: */ 343 if (m_pProgressBar) 344 m_pProgressBar->setValue(100); 345 /* Update details with error text if any: */ 346 if (m_pLabelDetails) 347 updateDetails(); 348 } 349 350 UINotificationDownloader *UINotificationDownloaderItem::downloader() const 351 { 352 return qobject_cast<UINotificationDownloader*>(m_pObject); 353 } 354 355 void UINotificationDownloaderItem::updateDetails() 356 { 357 AssertPtrReturnVoid(m_pLabelDetails); 358 const QString strDetails = downloader()->details(); 359 const QString strError = downloader()->error(); 360 const QString strFullDetails = strError.isNull() 361 ? strDetails 362 : QString("%1<br>%2").arg(strDetails, strError); 363 m_pLabelDetails->setText(strFullDetails); 364 if (!strError.isEmpty()) 365 { 366 m_fToggled = true; 367 m_pLabelDetails->setVisible(m_fToggled); 368 } 369 } 370 371 372 /********************************************************************************************************************************* 275 373 * Namespace UINotificationProgressItem implementation. * 276 374 *********************************************************************************************************************************/ … … 281 379 if (pObject->inherits("UINotificationProgress")) 282 380 return new UINotificationProgressItem(pParent, static_cast<UINotificationProgress*>(pObject)); 381 if (pObject->inherits("UINotificationDownloader")) 382 return new UINotificationDownloaderItem(pParent, static_cast<UINotificationDownloader*>(pObject)); 283 383 /* Handle defaults: */ 284 384 return new UINotificationObjectItem(pParent, pObject); -
trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjectItem.h
r90388 r90556 32 32 class QIRichTextLabel; 33 33 class QIToolButton; 34 class UINotificationDownloader; 34 35 class UINotificationObject; 35 36 class UINotificationProgress; … … 109 110 }; 110 111 112 /** UINotificationObjectItem extension for notification-downloader. */ 113 class UINotificationDownloaderItem : public UINotificationObjectItem 114 { 115 Q_OBJECT; 116 117 public: 118 119 /** Constructs notification-downloader item, passing @a pParent to the base-class. 120 * @param pDownloader Brings the notification-downloader this item created for. */ 121 UINotificationDownloaderItem(QWidget *pParent, UINotificationDownloader *pDownloader = 0); 122 123 protected: 124 125 /** Holds the progress-bar instance. */ 126 QProgressBar *m_pProgressBar; 127 128 private slots: 129 130 /** Handles signal about progress started. */ 131 void sltHandleProgressStarted(); 132 /** Handles signal about progress changed. 133 * @param uPercent Brings new progress percentage value. */ 134 void sltHandleProgressChange(ulong uPercent); 135 /** Handles signal about progress finished. */ 136 void sltHandleProgressFinished(); 137 138 private: 139 140 /** Holds the notification-downloader this item created for. */ 141 UINotificationDownloader *downloader() const; 142 143 /** Updates details. */ 144 void updateDetails(); 145 }; 146 111 147 /** Notification-object factory. */ 112 148 namespace UINotificationItem
Note:
See TracChangeset
for help on using the changeset viewer.