[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Solid - how to get path of storage device
From:       "Christopher Blauvelt" <cblauvelt () gmail ! com>
Date:       2008-06-11 2:10:43
Message-ID: ffa898c90806101910g405d3c52gbfe180ecb8d95e7c () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Tue, Jun 10, 2008 at 7:31 PM, David Boosalis <david.boosalis@gmail.com>
wrote:

> Hi Chris.
>
> The signal gets generated from a USB being plugged in.  I use the following
> to connect the signal to the slog given:
>
>   connect(DeviceNotifier::instance(),
>       SIGNAL(deviceAdded(const QString &)),
>       this,
>       SLOT(slotSolidDeviceChanged(const QString &)));
>
>   connect(Solid::DeviceNotifier::instance(),
>       SIGNAL(deviceRemoved(const QString &)),
>       this,
>       SLOT(slotSolidDeviceChanged(const QString &)));
>
> This was taken from the solid tutorial. Maybe I am getting an extraneous
> signal when I plug in the usb stick because the qDebug statement for
> filePath below prints nothing for hte filePath argument. I am using hte
> latest build of the depot for all my coding work.  You mentioned something
> about StorgeAccess::setup(), I'll research this call, as I am not sure where
> to put it.
>
> filePath() gives you the path to where the device is *mounted*.  The signal
you're receiving is sent when the device is plugged in, regardless of
whether it's mounted or not.  If you plug in your USB device, and it's not
mounted you catch the signal that a device was added but since it's not
mounted filePath() will return QString().

Try this in your slot:
qDebug() << "Device changed " << str;
  QString filePath;
  Solid::Device device(str);
  Solid::StorageAccess *accessStorage = device.as<Solid::StorageAccess>();
  if(storageAccess) {
     if(!storageAccess->isAccessible()) { //device is plugged in but not
mounted
         storageAccess->setup();
     }
     qDebug() << "File path is: " << storageAccess->filePath();
  }

[Attachment #5 (text/html)]

<br><br><div class="gmail_quote">On Tue, Jun 10, 2008 at 7:31 PM, David Boosalis \
&lt;<a href="mailto:david.boosalis@gmail.com">david.boosalis@gmail.com</a>&gt; \
wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, \
204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Hi Chris.<br><br>The signal \
gets generated from a USB being plugged in.&nbsp; I use the following to connect the \
signal to the slog given:<br><br>&nbsp; connect(DeviceNotifier::instance(), \
<br>&nbsp;&nbsp;&nbsp; &nbsp; SIGNAL(deviceAdded(const QString &amp;)),<br>

&nbsp;&nbsp;&nbsp; &nbsp; this, <br>&nbsp;&nbsp;&nbsp; &nbsp; \
SLOT(slotSolidDeviceChanged(const QString &amp;)));<br>&nbsp; <br>&nbsp; \
connect(Solid::DeviceNotifier::instance(), <br>&nbsp;&nbsp;&nbsp; &nbsp; \
SIGNAL(deviceRemoved(const QString &amp;)),<br>&nbsp;&nbsp;&nbsp; &nbsp; this, \
<br>&nbsp;&nbsp;&nbsp; &nbsp; SLOT(slotSolidDeviceChanged(const QString &amp;)));<br>

<br>This was taken from the solid tutorial. Maybe I am getting an extraneous signal \
when I plug in the usb stick because the qDebug statement for filePath below prints \
nothing for hte filePath argument. I am using hte latest build of the depot for all \
my coding work.&nbsp; You mentioned something about StorgeAccess::setup(), I&#39;ll \
research this call, as I am not sure where to put it.<br>

<br></blockquote></div>filePath() gives you the path to where the device is \
*mounted*.&nbsp; The signal you&#39;re receiving is sent when the device is plugged \
in, regardless of whether it&#39;s mounted or not.&nbsp; If you plug in your USB \
device, and it&#39;s not mounted you catch the signal that a device was added but \
since it&#39;s not mounted filePath() will return QString().<br> <br>Try this in your \
slot:<br>qDebug() &lt;&lt; &quot;Device changed &quot; &lt;&lt; str;<br>&nbsp; \
QString filePath;<br>&nbsp; Solid::Device device(str);<br>&nbsp; Solid::StorageAccess \
*accessStorage = <a href="http://device.as">device.as</a>&lt;Solid::StorageAccess&gt;();<br>
 &nbsp; if(storageAccess) {<br>&nbsp;&nbsp;&nbsp;&nbsp; \
if(!storageAccess-&gt;isAccessible()) { //device is plugged in but not \
mounted<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
storageAccess-&gt;setup();<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; \
qDebug() &lt;&lt; &quot;File path is: &quot; &lt;&lt; \
storageAccess-&gt;filePath();<br> &nbsp; }<br>



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic