Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.01 KB | None | 0 0
  1. diff --git a/kget/core/kget.cpp b/kget/core/kget.cpp
  2. index bc2a90b..48f48e8 100644
  3. --- a/kget/core/kget.cpp
  4. +++ b/kget/core/kget.cpp
  5. @@ -4,6 +4,7 @@
  6.     Copyright (C) 2007-2009 Lukas Appelhans <l.appelhans@gmx.de>
  7.     Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
  8.     Copyright (C) 2008 Dario Freddi <drf54321@gmail.com>
  9. +   Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
  10.  
  11.     This program is free software; you can redistribute it and/or
  12.     modify it under the terms of the GNU General Public
  13. @@ -740,6 +741,7 @@ TransferGroupScheduler * KGet::m_scheduler = new TransferGroupScheduler();
  14.  MainWindow * KGet::m_mainWindow = 0;
  15.  KUiServerJobs * KGet::m_jobManager = 0;
  16.  TransferHistoryStore * KGet::m_store = 0;
  17. +QHash<QString, QPixmap> KGet::m_pixmapCache;
  18.  
  19.  // ------ PRIVATE FUNCTIONS ------
  20.  KGet::KGet()
  21. @@ -1170,7 +1172,11 @@ bool KGet::safeDeleteFile( const KUrl& url )
  22.  KNotification *KGet::showNotification(QWidget *parent, const QString &eventType,
  23.                              const QString &text, const QString &icon, const QString &title, const KNotification::NotificationFlags &flags)
  24.  {
  25. -    return KNotification::event(eventType, title, text, KIcon(icon).pixmap(KIconLoader::SizeMedium), parent, flags);
  26. +    if (!m_pixmapCache.contains(icon)) {
  27. +        m_pixmapCache[icon] = KIcon(icon).pixmap(KIconLoader::SizeMedium);
  28. +    }
  29. +
  30. +    return KNotification::event(eventType, title, text, m_pixmapCache[icon], parent, flags);
  31.  }
  32.  
  33.  GenericObserver::GenericObserver(QObject *parent)
  34. diff --git a/kget/core/kget.h b/kget/core/kget.h
  35. index b1ca1b0..5a17a5f 100644
  36. --- a/kget/core/kget.h
  37. +++ b/kget/core/kget.h
  38. @@ -2,6 +2,7 @@
  39.  
  40.     Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
  41.     Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
  42. +   Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
  43.  
  44.     Based on:
  45.         kmainwidget.{h,cpp}
  46. @@ -408,6 +409,12 @@ class KGET_EXPORT KGet
  47.  
  48.          //pointer to the used TransferHistoryStore
  49.          static TransferHistoryStore *m_store;
  50. +
  51. +        /**
  52. +         * Caches pixmaps for faster retrieval
  53. +         * @note used in showNotifications and speeds up showing them
  54. +         */
  55. +        static QHash<QString, QPixmap> m_pixmapCache;
  56.  };
  57.  
  58.  class KGet::TransferData
  59. diff --git a/kget/core/transfer.cpp b/kget/core/transfer.cpp
  60. index 1e939e0..184c7f8 100644
  61. --- a/kget/core/transfer.cpp
  62. +++ b/kget/core/transfer.cpp
  63. @@ -44,6 +44,8 @@ const StatusStrings STATUSTEXTS[] = {
  64.  };
  65.  const QStringList STATUSICONS = QStringList() << "media-playback-start" << "view-history" << "process-stop" << "dialog-error" << "dialog-ok" << "media-playback-start" << "media-playback-pause";
  66.  
  67. +QHash<Job::Status, QPixmap> Transfer::m_statusPixmapCache;
  68. +
  69.  Transfer::Transfer(TransferGroup * parent, TransferFactory * factory,
  70.                     Scheduler * scheduler, const KUrl & source, const KUrl & dest,
  71.                     const QDomElement * e)
  72. @@ -315,7 +317,10 @@ void Transfer::setStatus(Job::Status jobStatus, const QString &text, const QPixm
  73.      }
  74.  
  75.      if (statusChanged || m_statusPixmap.isNull()) {
  76. -        m_statusPixmap = SmallIcon(STATUSICONS[jobStatus]);
  77. +        if (!m_statusPixmapCache.contains(jobStatus)) {
  78. +            m_statusPixmapCache[jobStatus] = SmallIcon(STATUSICONS[jobStatus]);
  79. +        }
  80. +        m_statusPixmap = m_statusPixmapCache[jobStatus];
  81.      }
  82.  
  83.      m_statusText = statusText;
  84. diff --git a/kget/core/transfer.h b/kget/core/transfer.h
  85. index cb83300..fbc120f 100644
  86. --- a/kget/core/transfer.h
  87. +++ b/kget/core/transfer.h
  88. @@ -364,6 +364,7 @@ class KGET_EXPORT Transfer : public Job
  89.  
  90.          QString m_statusText;
  91.          QPixmap m_statusPixmap;
  92. +        static QHash<Job::Status, QPixmap> m_statusPixmapCache;
  93.          QTime m_runningTime;
  94.  
  95.          TransferHandler * m_handler;
  96. diff --git a/kget/core/transfergroup.cpp b/kget/core/transfergroup.cpp
  97. index c02d074..b279b47 100644
  98. --- a/kget/core/transfergroup.cpp
  99. +++ b/kget/core/transfergroup.cpp
  100. @@ -23,6 +23,7 @@
  101.  #include <QDateTime>
  102.  #include <QDomElement>
  103.  
  104. +QHash<QString, QPixmap> TransferGroup::m_pixmapCache;;
  105.  
  106.  TransferGroup::TransferGroup(TransferTreeModel * model, Scheduler * parent, const QString & name)
  107.      : JobQueue(parent),
  108. @@ -76,6 +77,20 @@ bool TransferGroup::supportsSpeedLimits()
  109.      return true;
  110.  }
  111.  
  112. +void TransferGroup::setIconName(const QString &name)
  113. +{
  114. +    m_iconName = name;
  115. +}
  116. +
  117. +QPixmap TransferGroup::pixmap()
  118. +{
  119. +    if (!m_pixmapCache.contains(m_iconName)) {
  120. +        m_pixmapCache[m_iconName] = KIcon(m_iconName).pixmap(32);
  121. +    }
  122. +
  123. +    return m_pixmapCache[m_iconName];
  124. +}
  125. +
  126.  void TransferGroup::setStatus(Status queueStatus)
  127.  {
  128.      JobQueue::setStatus(queueStatus);
  129. diff --git a/kget/core/transfergroup.h b/kget/core/transfergroup.h
  130. index 81e2bc1..85c0cf0 100644
  131. --- a/kget/core/transfergroup.h
  132. +++ b/kget/core/transfergroup.h
  133. @@ -246,7 +246,7 @@ class KGET_EXPORT TransferGroup : public JobQueue
  134.           * Set the group's icon
  135.          * @param name the icon's name
  136.           */
  137. -        void setIconName(const QString &name) {m_iconName = name;}
  138. +        void setIconName(const QString &name);
  139.  
  140.          /**
  141.           * @returns the group's icon's name
  142. @@ -256,7 +256,7 @@ class KGET_EXPORT TransferGroup : public JobQueue
  143.          /**
  144.           * @return the group's icon
  145.           */
  146. -        QPixmap pixmap() {return KIcon(m_iconName).pixmap(32);}
  147. +        QPixmap pixmap();
  148.  
  149.          /**
  150.           * @return the handler associated with this group
  151. @@ -316,6 +316,7 @@ class KGET_EXPORT TransferGroup : public JobQueue
  152.          QString m_iconName;
  153.          QString m_defaultFolder;
  154.          QRegExp m_regExp;
  155. +        static QHash<QString, QPixmap> m_pixmapCache;
  156.  #ifdef HAVE_NEPOMUK
  157.          QStringList m_tags;
  158.  #endif //HAVE_NEPOMUK
  159. diff --git a/kget/ui/transfersviewdelegate.cpp b/kget/ui/transfersviewdelegate.cpp
  160. index 40d5ae7..f10ab95 100644
  161. --- a/kget/ui/transfersviewdelegate.cpp
  162. +++ b/kget/ui/transfersviewdelegate.cpp
  163. @@ -48,6 +48,11 @@ GroupStatusButton::GroupStatusButton(const QModelIndex & index, QWidget * parent
  164.      setAttribute(Qt::WA_NoSystemBackground);
  165.  }
  166.  
  167. +void GroupStatusButton::resetIconCache()
  168. +{
  169. +    m_iconCache.clear();
  170. +}
  171. +
  172.  void GroupStatusButton::checkStateSet()
  173.  {
  174.  //     kDebug(5001) << "GroupStatusButton::checkStateSet";
  175. @@ -140,9 +145,11 @@ void GroupStatusButton::paintEvent(QPaintEvent * event)
  176.          p.drawEllipse(rect().x()+5, rect().y()+4, rect().width()-10, rect().width()-10);
  177.      }
  178.  
  179. -    p.drawPixmap(rect().topLeft() + QPoint(offset, offset - 1),
  180. -                 icon().pixmap(m_iconSize, isChecked() || m_status == Blinking ?
  181. -                                           QIcon::Normal : QIcon::Disabled));
  182. +    const QIcon::Mode iconMode = ((isChecked() || (m_status == Blinking)) ? QIcon::Normal : QIcon::Disabled);
  183. +    if (!m_iconCache.contains(iconMode)) {
  184. +        m_iconCache[iconMode] = icon().pixmap(m_iconSize, iconMode);
  185. +    }
  186. +    p.drawPixmap(rect().topLeft() + QPoint(offset, offset - 1), m_iconCache[iconMode]);
  187.  }
  188.  
  189.  void GroupStatusButton::timerEvent(QTimerEvent *event)
  190. diff --git a/kget/ui/transfersviewdelegate.h b/kget/ui/transfersviewdelegate.h
  191. index 7b9e1f0..86262ae 100644
  192. --- a/kget/ui/transfersviewdelegate.h
  193. +++ b/kget/ui/transfersviewdelegate.h
  194. @@ -32,6 +32,13 @@ class GroupStatusButton : public QToolButton
  195.      public:
  196.          GroupStatusButton(const QModelIndex &index, QWidget *parent);
  197.  
  198. +        /**
  199. +         * GroupStatusButton uses a cache for the set icon, if the
  200. +         * icon changes the cache still remains the same.
  201. +         * To use the new icon you have to call resetCache first.
  202. +         */
  203. +        void resetIconCache();
  204. +
  205.      protected:
  206.          void checkStateSet();
  207.          void enterEvent(QEvent * event);
  208. @@ -44,7 +51,8 @@ class GroupStatusButton : public QToolButton
  209.          QModelIndex m_index;
  210.  
  211.          int m_timerId;
  212. -        int m_iconSize;
  213. +        const int m_iconSize;
  214. +        QHash<int, QPixmap> m_iconCache;
  215.  
  216.          float m_gradientId;
  217.  };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement