LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-29-2006, 09:41 AM   #1
seran
Member
 
Registered: Aug 2004
Location: Bangalore
Posts: 64

Rep: Reputation: 16
Showing a dialog box on hotplug event?


Hello,

I have a USB Transcend pendrive capable of storing 128MB size. I have written a script which will be read by the automount program
to mount the pendrive at a location /home/seran/removable/usbthumb.

If the pen drive is plugged in "usbthumb" directory will be created.
If the pen drive is unplugged the "usbthumb" directory will disappear.

After plugging in the pendrive all the files are listed at the location /home/seran/removable/usbthumb.

Now I have to show a window or dialog box which should popup
whenever the pen drive is plugged in. I have written a simple
dialog designed using Qt (modal dialog).

To achieve this I added the following lines in /etc/hotplug/usb.agent script at the end of "add)" section:
Quote:
# If the directory was created by automount
if [ -d /home/seran/removable/usbthumb ]
then
# Trying to show dialog
/home/seran/showdialog && mesg "Successfully displayed"
fi
But the dialog never appears on screen. I tried using "exec" also, but didn't succeed. The execution of "/home/seran/showdialog" always fails.

I don't understand why this happens?

In short:
A dialog box should appear on screen whenever I plug-in my pendrive.

How do I do this? Any ideas. Please provide some suggestions.

My machine is RedHat 9.0, shell bash.

Thanks
Seran
 
Old 06-29-2006, 11:17 AM   #2
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
You could give 'xmessage' a go.
Code:
...
# Trying to show dialog
DISPLAY=:0 && xmessage "Success"
...
This will ensure the local X display is used, and then display a message box.
Hope that helps.
 
Old 06-30-2006, 07:22 AM   #3
seran
Member
 
Registered: Aug 2004
Location: Bangalore
Posts: 64

Original Poster
Rep: Reputation: 16
Thanks for the reply. But this too doesn't work.

If I call a plain shell script (without any X Window related binary) from usb.agent there are no issues.

If I call any X related binaries (like xterm, xcalc, and my Qt UI) it fails.

I suspect "hotplug" doesn't have permissions to enter X's territory.

But I achieved this in other way.

1. I added a service inside /etc/init.d/ called "showusbui"
2. This service will start a shell script in background which will check for the pendrive insertion (infinite loop). If the pendrive is inserted the directory "/home/seran/removable/usbthumb/" will be created. Then it is pop's up the UI.

Here is the shell script which runs in background.
Quote:
#!/bin/sh

while true
do
if [ -d /home/seran/removable/usbthumb ]
then
PID=`pidof showdialog`

# UI is not running.
if [ "$PID" == "" ]
then
/home/seran/showdialog
fi
fi
done
And I believe there are lots to learn about "hotplug".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dialog box no longer appears Jongi SUSE / openSUSE 4 04-21-2006 07:55 AM
Dialog box help!!!!!!!! HopelessLinuxNewbie Fedora 1 08-24-2005 11:48 AM
Dialog box scripting.... r_jensen11 Programming 2 01-25-2004 06:40 PM
Hotplug event drop my intrnet connection! Nik0s Linux - Networking 12 01-25-2004 02:11 PM
Creating an x windows dialog box antken Programming 5 09-29-2003 01:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration