-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use system file type specific icons in contents tab #6156
Conversation
Sample screen shot please? |
PR Updated: replace |
👍 good job |
I was so pumped but unfortunately this doesn't work on Windows with Qt 5.7.1(didn't test qt4). |
Possible explanation here. It seems QFileIconProvider works if the file actually exists on disk. |
And a stale Qt bug report: https://bugreports.qt.io/browse/QTBUG-25319 |
This is pity, of course. The feature is really nice and useful.... Except of patched Qt for the Windows builds or custom implementation of the same function I have no other ideas so far. |
The only choice here it to do this only for the platforms that support it and fallback to our current code for Windows. I'm in no mood to implement it in WINAPI. Supposedly macOS should work too. |
@okeatime, can you tell us, please, does it work in OSX? |
src/gui/torrentcontentmodel.h
Outdated
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; | ||
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; | ||
virtual QModelIndex parent(const QModelIndex &index) const; | ||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
override
's instead of virtual
? No class seems to inherit from this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just reformatted the code, that was written before C++11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, was just wondering if you want to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, sorry. Not in this PR.
Yes, it does. |
Apparently, Qt build from cache in AppVeyor does not contain qwinextras module (why qmake is silent on this during its run?). If I use pre-installed Qt (see the last commit) it compiles, but fails during linking because QtSingleApplication was linked with static runtime (BTW, why?) while the pre-installled Qt is linked with dynamic one. I give up. |
I can do kind of a hack: declare Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon); (which is exported from QtGui library) and use it without QWinExtras module. What do you think? |
The hack is in its own commit now. |
@sledgehammer999, I think we need your, as Windows packages, opinion here regarding this hack: would you prefer to use the additional Qt module WinExtras (albeit very small one) and update AppVeyor cached Qt package to include it, or use this hack? Actually, the hack is identical to the internals of WinExtras module. |
Thanks, will check one more time a bit later. |
I prefer this option. |
Because I forgot that for a long time I'm applying this patch locally. Obviously, current implementation will not work outside of Plasma even if that patch get accepted. Probably, I better return to |
@zywo, tell, please, in what environment did you test? |
@evsh |
+1 Just wait a bit, I'm in the process of building+uploading new package for appveyor with WinExtras. Then you can also remove the winextras check too. |
Super! Could you ping me, please, when the new image is ready? |
@evsh new files are uploaded. I also updated the appveyor config you use msvc2017, so be sure to rebase on top of master. |
@sledgehammer999: thanks! PR updated: QWinExtras module is used unconditionally, icons are shown unconditionally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor things due to the rebase.
Otherwise, it is good for merging.
src/gui/advancedsettings.cpp
Outdated
@@ -37,6 +37,7 @@ | |||
#include "base/bittorrent/session.h" | |||
#include "base/preferences.h" | |||
#include "gui/mainwindow.h" | |||
#include "gui/torrentcontentmodel.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a leftover?
src/gui/torrentcontentmodel.cpp
Outdated
@@ -41,27 +50,60 @@ | |||
|
|||
namespace | |||
{ | |||
const char showSystemFileIconsSettingKey[] = "Preferences/Advanced/showSystemFileIcons"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a leftover too.
src/gui/torrentcontentmodel.h
Outdated
@@ -37,8 +37,10 @@ | |||
#include <QVariant> | |||
|
|||
#include "base/bittorrent/torrentinfo.h" | |||
#include "base/settingvalue.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover
src/gui/torrentcontentmodel.cpp
Outdated
@@ -74,6 +77,7 @@ namespace | |||
class WinShellFileIconProvider: public UnifiedFileIconProvider | |||
{ | |||
public: | |||
using QFileIconProvider::icon; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this belongs to the previous commit?
src/gui/torrentcontentmodel.cpp
Outdated
* @brief Tests whether QFileIconProvider actually works | ||
* | ||
* Some QPA plugins do not implement QPlatformTheme::fileIcon(), and | ||
* QFileIconProvider::icon() returns empty icons as the result. Here we asks it for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "ask"
@sledgehammer999: done. Sorry for the carelessness. |
src/gui/torrentcontentmodel.cpp
Outdated
#include "guiiconprovider.h" | ||
#include "base/settingsstorage.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both of us missed this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The icon is determined via QFileIconProvider using filename extension only.
If built-in QFileIconProvider does not seem to work, use custom implementation which queries mime database.
Thx |
Thanks everyone! |
Fix for QTBUG-25319 will be in Qt 5.9.2. I'll submit a corresponding PR. |
Finally. Although that Qt shortcoming was mentioned/known a long while ago. At least the fixed it. |
@evsh I have just realised that this always returns blank icons on macOS for anything but folders. |
@vit9696 thanks for pointing this out. Unfortunately, I can't build qBt in MacOS so can not look into it right now. Maybe next week... |
@evsh, ok, I tracked the issue down, and the merged code simply makes no sense to me from now on. This line building Obviously icon lookup will always fail when the downloaded file resides in a folder different from the working directory. That's because What needs to be done here (especially given that one should be able to see the icons before downloading anything) is just a plain extension-based lookup. So I enforced
So far so good, but Given the overall code craziness, could you please rework this? If you want to use file-based icon matching, please provide a valid file path. Otherwise this should be eliminated for good, along with the ugly test attempting to achieve nothing. Here is a basic patch required to get things work on macOS. I could submit a pull-request with just this to make it in time for 3.4.0. Or it could be used as a reference for the refactoring of this code by somebody else. CC @Chocobo1, @glassez, @LordNyriox, @sledgehammer999, @thalieht. |
@vit9696, thanks for the investigation!
This makes no sense to me. Are you saying that the
Lookup by file extension has to work with non-existing files.
This means QTBUG-25319 affects MacOS too.
Because it's a part of |
I am only talking about
Yes, but what is the point of doing this when you already have mime-based search? This is not going to do any better unless you actually have the file at least partially downloaded, pass the valid path, have the data-based detection enabled. Otherwise it is just unnecessary code duplication.
QFileIconProvider is just a spike that helps nothing when you provide invalid paths that will never become valid to it. |
Thanks, understood.
Mime database does not exist on Windows, while
Uniform interface. So, |
That does not work on anything but a couple of Linux distros :D |
It works on Windows too (Qt 5.9.2 and later). |
Again a bit of eye-candy. Torrent contents tab shows icons for items, but icons of two types only: directory and text file. But we can get correct icon from the system mime database. The icon is determined via QFileIconProvider using filename extension only.
Perhaps default icon without mime database should be changed to "application/octet-stream" too.