Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, December 2006
shell context menu


Message 1 in thread

Hello,
	I'm developing some application and I would like to use native shell 
context menu - in Windows when you right click on file in Explorer, in 
Linux something similar in Konqueror (or what's the right name for the 
Linux explorer).
	Is is Qt some function to popup native context menu or I have to make 
it myself by #ifdefs (for Windows and Linux)? And if by myself - do you 
know where can I found some example preferably in C++ with use of WinAPI 
(with no use of MFC and so on).
	I've found only this (1) 
http://www.microsoft.com/msj/0497/wicked/wicked0497.aspx and this (2) 
http://www.codeproject.com/shell/shellcontextmenu.asp . In the first 
case there are (probably) three examples but none of them works all 
right - some menu items are missing and some have not any text and icon. 
The second one looks that works like I want but use MFC.
	So now I have three options - some Qt function, #include somehow second 
example or use second example as DLL. If you have any advice to options 
I wrote or something else... thank you.

--
 [ signature omitted ] 

Message 2 in thread

Isshou wrote:
> Hello,
> 	I'm developing some application and I would like to use 
> native shell 
> context menu - in Windows when you right click on file in 
> Explorer, in 
> Linux something similar in Konqueror (or what's the right 
> name for the Linux explorer).

There is no such thing as '_the_ linux explorer'. There are 
several tools doing 'explorer things' and I am not aware of
a unified way to extend them ...

> 	Is is Qt some function to popup native context menu or 

... so I doubt there's a Qt solution for that.

> I have to make  it myself by #ifdefs (for Windows and Linux)?

Yes. And note there are users not using any kind of 'explorer'.

> And if by myself - do you know where can I found some example
> preferably in C++ with use of WinAPI 

Extending the context menu in the Windows Explorer is just
setting a registry entry in 
HKEY_CLASSES_ROOT\Directory\shell\<Name>\Command.

I doubt one needs MFC for doing so.

Regards
Andre'

--
 [ signature omitted ] 

Message 3 in thread

On 01.12.06 09:45:04, Isshou wrote:
> 	I'm developing some application and I would like to use native shell context 
> menu - in Windows when you right click on file in Explorer, in Linux something 
> similar in Konqueror (or what's the right name for the Linux explorer).

Just to make you aware of this: There's no such thing as "linux
explorer", there are tons of file managers out there for *nix. Some of
them also include the capability to display files like konqueror can,
but there's certainly no "native shell context menu" on Linux.

> 	Is is Qt some function to popup native context menu or I have to make it 
> myself by #ifdefs (for Windows and Linux)?

See above, you can pretty much leave linux out, unless you make your
application depend on konqueror, nautilus, xffm4 or any other file
manager for linux.

Andreas

-- 
 [ signature omitted ] 

Message 4 in thread

> See above, you can pretty much leave linux out, unless you make your
> application depend on konqueror, nautilus, xffm4 or any other file
> manager for linux.
>
> Andreas

	well, perhaps "depend" is somewhat too strong a word -- something
like contextual menu integration isn't necessarily a showstopper like some
things.

	if one has a linux user savvy enough to run something other than
GNOME or KDE, chances are they can look at the GNOME and KDE examples and
google for a suitable analogue.


	d
	.

--
 [ signature omitted ] 

Message 5 in thread

Ok, thanks. I will try to modify the second example I found. For MFC 
there is only CMenu and CWnd class so I will try to "remove" them 
somehow. And for Linux I will make something special :) .

--
 [ signature omitted ] 

Message 6 in thread

> Ok, thanks. I will try to modify the second example I found. For MFC 
> there is only CMenu and CWnd class so I will try to "remove" them 

What's wrong with those? You are going to develop a Windows-only solution 
anyway (probably #ifdef'ed). So why not just using MFC inside that part?


> somehow. And for Linux I will make something special :) .

Most often it is better to implement such features as an enhencment and 
not as a requirement. If you make a solution for "your" linux and windows 
- what i.e. about MAC-OS? Maybe in future even more OSes will be supported 
- what about those?

To come to my point: Be careful with system-dependend #ifdef's.
My very personal point of view: You can use those parts, but don't make 
your software depend on it :-)

Regards,
Malte

--
 [ signature omitted ] 

Message 7 in thread

> To come to my point: Be careful with system-dependend #ifdef's.
> My very personal point of view: You can use those parts, but don't make 
> your software depend on it :-)

Or take it to the next step:

- Abstract those parts away in a separate class with implementation
   independent interface.
- Throw a compiler error or at least an assert for a part that's not yet
   implemented for the current platform.

I usually do the latter one when using platform dependent ifdefs.

Martin
-- 
 [ signature omitted ] 

Message 8 in thread

>> Ok, thanks. I will try to modify the second example I found. For MFC 
>> there is only CMenu and CWnd class so I will try to "remove" them 
> 
> What's wrong with those? You are going to develop a Windows-only solution 
> anyway (probably #ifdef'ed). So why not just using MFC inside that part?

Nothing is wrong with MFC (btw I don't like it very much :) ) but I 
don't want to have unnecessary library dependencies.

>> somehow. And for Linux I will make something special :) .
> 
> Most often it is better to implement such features as an enhencment and 
> not as a requirement. If you make a solution for "your" linux and windows 
> - what i.e. about MAC-OS? Maybe in future even more OSes will be supported 
> - what about those?

For Linux and Mac-OS (or simply other OS than Windows) I will do some 
"general shell" menu. And Mac-OS - I have no possibility to test on this 
OS so for now no care about this system.

> To come to my point: Be careful with system-dependend #ifdef's.
> My very personal point of view: You can use those parts, but don't make 
> your software depend on it :-)

This shell extension will be for some time only one platform dependent 
feature. But it will be not very long time :) because next will be icon 
extraction. And if I understand it well then Linux doesn't have any 
icons for files (maybe in some directory externally). So for Linux I 
will use QFileIconProvider or I will find out where icons are if they 
really are somewhere :) .

> Regards,
> Malte
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

Thank you.

And by the way I finally modified the MFC solution so it's working only 
with user32 and shell32 libraries :) . But I have strange problem with 
#ifdef Q_WS_WIN - in one cpp file it works normally but in another it 
looks like it's not defined and I don't know why. I have to define it 
explicitly (only for testing purposes).

--
 [ signature omitted ] 

Message 9 in thread

Isshou schrieb:
> But I have strange problem with 
> #ifdef Q_WS_WIN - in one cpp file it works normally but in another it 
> looks like it's not defined and I don't know why.

Make sure QtGlobal is included...?

Martin

-- 
 [ signature omitted ] 

Message 10 in thread

> Isshou schrieb:
>> But I have strange problem with #ifdef Q_WS_WIN - in one cpp file it 
>> works normally but in another it looks like it's not defined and I 
>> don't know why.
> 
> Make sure QtGlobal is included...?
> 
> Martin
> 

Yes, that's it, thank you very much. I haven't declared there any Qt class.

--
 [ signature omitted ] 

Message 11 in thread

> And by the way I finally modified the MFC solution so it's working only 
> with user32 and shell32 libraries :) . But I have strange problem with 
> #ifdef Q_WS_WIN - in one cpp file it works normally but in another it 
> looks like it's not defined and I don't know why. I have to define it 
> explicitly (only for testing purposes).

You have to _at least_  #include <QtGlobal> or any other Qt-Header to use 
Q_OS_*/Q_WS_*-defines.
I would not use Q_WS_WIN but Q_OS_WIN32, Q_OS_LINUX etc ... But above 
statement is true for both variants :-)

Regards,
Malte


--
 [ signature omitted ] 

Message 12 in thread

On Fri, 1 Dec 2006, Isshou wrote:

> Hello,
> 	I'm developing some application and I would like to use native shell
> context menu - in Windows when you right click on file in Explorer, in
> Linux something similar in Konqueror (or what's the right name for the
> Linux explorer).

	as andre pointed out, there isn't a single "linux explorer", nor
even an API for getting at the kind of thing you're looking for.  nautilus
(GNOME's file browser) does things one way, konqueror (KDE's) another, and
so on.  you could have the user select at install time, e.g., or leave it
for them to optionally wire-up, or maybe try to be sneaky and look at
/etc/init.d/ for evidence of gdm (GNOME) or kdm (KDE) and try to guess.

	handling those GNOME and KDE, however, does net you most linux
users.  i just had to set this up for a linux-based Qt app -- here's some
lamelamelame snippets from my release docs that explains nautilus and
konqueror ...

-------------------------------------------------------------------

contextual menu support in KDE's konqueror file-browser:
   the file "NFSv4-ACL.desktop" in this directory provides a simple
   addition to KDE contextual menus (i.e., right-click menus) so that
   the NFSv4 ACL tool can be easily used with konqueror.

   to enable this addition to the menu, copy "NFSv4-ACL.desktop" into,
   e.g., /opt/kde3/share/apps/konqueror/servicemenus/, or where you
   choose to install servicemenus for konqueror.

   to set a custom icon for the menuitem, copy the file
   "images/citi-icon.gif" to /opt/kde3/share/apps/konqueror/pics/.


contextual menu support in GNOME's Nautilus file-browser:
   the file "NFS4v4-ACL.nautilus" in this directory is a simple script
   which enables contextual menu (e.g., right-click) support for
   launching the NFSv4 ACL tool with Nautilus.

   to enable this addition, read the top of the file
   "NFSv4-ACL.nautilus".  most likely, you'll just need to make the
   file executable and copy it to ~/.gnome2/nautilus-scripts/.

-------------------------------------------------------------------

contents of .ini-style NFSv4-ACL.desktop (KDE integration):

; this file should go in:  /opt/kde3/share/apps/konqueror/servicemenus/
;
; to set a custom icon for this, copy the file:  ./images/citi-icon.gif
; into:  /opt/kde3/share/apps/konqueror/pics/

[Desktop Entry]
ServiceTypes=all/all
Actions=editNFSv4ACL

[Desktop Action editNFSv4ACL]
Name=Edit NFSv4 ACL
Icon=/opt/kde3/share/apps/konqueror/pics/citi-icon.gif
Exec=nfs4-acl-editor %f

-------------------------------------------------------------------

contents of shell-script-style NFSv4-ACL.nautilus (GNOME integration):

#!/bin/sh
#
# NFSv4 ACL tool contextual-menu support for Nautilus/GNOME:
#
# - to install with Nautilus < 1.0.5, copy this to ~/Nautilus/scripts/
# - to install with a newer Nautilus, copy this to ~/.gnome2/nautilus-scripts/
#
# - in all cases, make that file executable with: chmod +x <file>
#
# i don't use GNOME or nautilus, so it might be ~/.gnome/ or something.
#
#  david m. richter / nfsv4@xxxxxxxxxxxxx

echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | xargs -L 1 nfs4-acl-editor

-------------------------------------------------------------------

	... one thing to note about my GNOME entry above: the xargs
statement will serially launch the editor program, once for each file
highlighted.  that is, when one selects like 10 files, right-clicks on any
one of them and chooses the editor program.  that was the way mine needed
to behave, but one could make it so that they all launched simultaneously,
e.g.


	good luck,

	d
	.

--
 [ signature omitted ]