[Qt-interest] icons for files

Marco Borm qt-lists at retrodesignfan.eu
Sat May 9 10:55:50 CEST 2009


Hi Puneet,

I see that this is needed because the QFileIconProvider and/or QFileInfo 
doesn't have any api for non localfiles, but I would call the result a 
more a hack.
With if multiple instances of your application maybe different users ... 
you will come into trouble.
Maybe adding the current pid to the filename is enough to fix that.

So it would be a good idea if you send a feature request for a 
QAbstractFileInfo extension to Nokia.
The QFileIconProvider should be changed to accept that, so everybody is 
able to write his own "QFileInfo".
This should be possible without breaking the ABI compatibility.
Additionally QFileInfo should inherit from that QAbstractFileInfo, but I 
don't think this is possible before Qt5.

Greetings,
Marco

Puneet Bisht wrote:
> thanks  Tanguy Krotoff,
>
> the code really works .
>
>
>   
>> Then you can create a temporary file on the local harddrive with the
>> same extension as the remote file.
>> This way QFileIconProvider will give you the right icon.
>>
>> here some code
>>
>>
>> QIcon fileExtensionIcon(const QString & extension) const {
>> 	static QFileIconProvider iconProvider;
>>
>> 	QIcon icon;
>>
>> 	QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() +
>> QCoreApplication::applicationName() + "_XXXXXX." + extension);
>> 	tmpFile.setAutoRemove(false);
>>
>> 	if (tmpFile.open()) {
>> 		QString fileName = tmpFile.fileName();
>> 		tmpFile.write(QByteArray());
>> 		tmpFile.close();
>>
>> 		icon = iconProvider.icon(QFileInfo(fileName));
>>
>> 		tmpFile.remove();
>> 	} else {
>> 		qCritical() << __FUNCTION__ << "Error: couldn't write temporary
>> file:" << tmpFile.fileName();
>> 	}
>>
>> 	return icon;
>> }
>>
>>
>> On Tue, May 5, 2009 at 2:27 PM, Puneet Bisht <pbisht at nivio.com> wrote:
>>     
>>> thanks for your reply
>>>
>>> i have already tried QFileIconProvider , but the problem is ,it requires
>>> a
>>> QFileInfo object and the file i want to show is on the server ,so i am
>>> confused how to get the QFileInfo object for that file .
>>>
>>> is there any other way
>>>
>>>
>>>       
>>>> QFileIconProvider is probably what you are looking for:
>>>> http://doc.trolltech.com/4.5/qfileiconprovider.html
>>>>
>>>> Jens
>>>>
>>>>
>>>> "Puneet Bisht" <pbisht at nivio.com> wrote in message
>>>> news:6977.192.168.5.2.1241097508.squirrel at webmail.nivio.com...
>>>>         
>>>>> hi all,
>>>>>
>>>>> i m working on a ftp application.
>>>>> i m showing files on a server using qlistwidget, now i want to set
>>>>> icons
>>>>> for files.
>>>>> can anybody tell me how can i set system provided icons for a file
>>>>> according to its extension e,g pdf,mp3 ...
>>>>>
>>>>> here i m using
>>>>> item->setIcon(style()->standardIcon(QStyle::SP_DirIcon,0,this)); for
>>>>> directories and
>>>>> item->setIcon(style()->standardIcon(QStyle::SP_FileIcon,0,this)); for
>>>>> file
>>>>>
>>>>> but i want to show different icons according to file extension.
>>>>>
>>>>> thanks in advance
>>>>>
>>>>> puneet
>>>>>           
>>>> --
>>>> Jens Bache-Wiig - jbache at trolltech.com
>>>>
>>>> _______________________________________________
>>>> Qt-interest mailing list
>>>> Qt-interest at trolltech.com
>>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>>
>>>>         
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at trolltech.com
>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>
>>>       
>>
>> --
>> Tanguy Krotoff <tkrotoff at gmail.com>
>> +33 6 68 42 70 24
>>
>>     
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>   




More information about the Qt-interest-old mailing list