Changeset 14195
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/utils.cc
r13730 r14195 13 13 #include <iostream> 14 14 15 #ifdef WIN32 16 #include <windows.h> 17 #include <shellapi.h> 18 #endif 19 15 20 #include <QApplication> 16 21 #include <QDataStream> … … 20 25 #include <QInputDialog> 21 26 #include <QObject> 27 #include <QPixmapCache> 22 28 #include <QSet> 23 29 #include <QStyle> … … 31 37 **** 32 38 ***/ 39 40 #if defined(WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 41 // Should be in QtWinExtras soon, but for now let's import it manually 42 extern QPixmap qt_pixmapFromWinHICON(HICON icon); 43 #endif 33 44 34 45 QString … … 56 67 } 57 68 58 const QIcon& 69 #ifdef WIN32 70 namespace 71 { 72 void 73 addAssociatedFileIcon (const QFileInfo& fileInfo, UINT iconSize, QIcon& icon) 74 { 75 QString const pixmapCacheKey = QLatin1String ("tr_file_ext_") + 76 QString::number (iconSize) + "_" + fileInfo.suffix (); 77 QPixmap pixmap; 78 if (!QPixmapCache::find (pixmapCacheKey, &pixmap)) 79 { 80 const QString filename = fileInfo.fileName (); 81 82 SHFILEINFO shellFileInfo; 83 if (::SHGetFileInfoW ((const wchar_t*) filename.utf16 (), FILE_ATTRIBUTE_NORMAL, 84 &shellFileInfo, sizeof(shellFileInfo), 85 SHGFI_ICON | iconSize | SHGFI_USEFILEATTRIBUTES) != 0) 86 { 87 if (shellFileInfo.hIcon != NULL) 88 { 89 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 90 pixmap = qt_pixmapFromWinHICON (shellFileInfo.hIcon); 91 #else 92 pixmap = QPixmap::fromWinHICON (shellFileInfo.hIcon); 93 #endif 94 ::DestroyIcon (shellFileInfo.hIcon); 95 } 96 } 97 98 QPixmapCache::insert (pixmapCacheKey, pixmap); 99 } 100 101 if (!pixmap.isNull ()) 102 icon.addPixmap (pixmap); 103 } 104 } // namespace 105 #endif 106 107 QIcon 59 108 Utils :: guessMimeIcon( const QString& filename ) 60 109 { 110 #ifdef WIN32 111 QIcon icon; 112 113 if (!filename.isEmpty ()) 114 { 115 const QFileInfo fileInfo (filename); 116 117 addAssociatedFileIcon (fileInfo, SHGFI_SMALLICON, icon); 118 addAssociatedFileIcon (fileInfo, 0, icon); 119 addAssociatedFileIcon (fileInfo, SHGFI_LARGEICON, icon); 120 } 121 122 if (icon.isNull ()) 123 icon = QApplication::style ()->standardIcon (QStyle::SP_FileIcon); 124 125 return icon; 126 #else 61 127 enum { DISK, DOCUMENT, PICTURE, VIDEO, ARCHIVE, AUDIO, APP, TYPE_COUNT }; 62 128 static QIcon fallback; … … 117 183 118 184 return fallback; 185 #endif 119 186 } 120 187 -
trunk/qt/utils.h
r14150 r14195 32 32 public: 33 33 static QString remoteFileChooser( QWidget * parent, const QString& title, const QString& myPath, bool dir, bool local ); 34 static const QIcon&guessMimeIcon( const QString& filename );34 static QIcon guessMimeIcon( const QString& filename ); 35 35 // Test if string is UTF-8 or not 36 36 static bool isValidUtf8 ( const char *s );
Note: See TracChangeset
for help on using the changeset viewer.