• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

  • sources
  • kde-4.14
  • kdelibs
  • kio
  • kio
kautomount.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "kautomount.h"
20 #include "krun.h"
21 #include "kdirwatch.h"
22 #include "kio/job.h"
23 #include "kio/jobuidelegate.h"
24 #include <kdirnotify.h>
25 #include <kdebug.h>
26 #include <kmountpoint.h>
27 
28 /***********************************************************************
29  *
30  * Utility classes
31  *
32  ***********************************************************************/
33 
34 class KAutoMountPrivate
35 {
36 public:
37  KAutoMountPrivate(KAutoMount *qq, const QString &device, const QString& mountPoint,
38  const QString &desktopFile, bool showFileManagerWindow)
39  : q(qq), m_strDevice(device), m_desktopFile(desktopFile), m_mountPoint(mountPoint),
40  m_bShowFilemanagerWindow(showFileManagerWindow)
41  { }
42 
43  KAutoMount *q;
44  QString m_strDevice;
45  QString m_desktopFile;
46  QString m_mountPoint;
47  bool m_bShowFilemanagerWindow;
48 
49  void slotResult( KJob * );
50 };
51 
52 KAutoMount::KAutoMount( bool _readonly, const QByteArray& _format, const QString& _device,
53  const QString& _mountpoint, const QString & _desktopFile,
54  bool _show_filemanager_window )
55  : d(new KAutoMountPrivate(this, _device, _mountpoint, _desktopFile, _show_filemanager_window))
56 {
57  KIO::Job* job = KIO::mount( _readonly, _format, _device, _mountpoint );
58  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)) );
59 }
60 
61 KAutoMount::~KAutoMount()
62 {
63  delete d;
64 }
65 
66 void KAutoMountPrivate::slotResult( KJob * job )
67 {
68  if ( job->error() ) {
69  emit q->error();
70  job->uiDelegate()->showErrorMessage();
71  } else {
72  const KMountPoint::List mountPoints (KMountPoint::currentMountPoints());
73  KMountPoint::Ptr mp = mountPoints.findByDevice(m_strDevice);
74  // Mounting devices using "LABEL=" or "UUID=" will fail if we look for
75  // the device using only its real name since /etc/mtab will never contain
76  // the LABEL or UUID entries. Hence, we check using the mount point below
77  // when device name lookup fails. #247235
78  if (!mp) {
79  mp = mountPoints.findByPath(m_mountPoint);
80  }
81 
82  if (!mp) {
83  kWarning(7015) << m_strDevice << "was correctly mounted, but findByDevice() didn't find it."
84  << "This looks like a bug, please report it on http://bugs.kde.org, together with your /etc/fstab and /etc/mtab lines for this device";
85  } else {
86  KUrl url(mp->mountPoint());
87  //kDebug(7015) << "KAutoMount: m_strDevice=" << m_strDevice << " -> mountpoint=" << mountpoint;
88  if ( m_bShowFilemanagerWindow ) {
89  KRun::runUrl( url, "inode/directory", 0 /*TODO - window*/ );
90  }
91  // Notify about the new stuff in that dir, in case of opened windows showing it
92  org::kde::KDirNotify::emitFilesAdded( url.url() );
93  }
94 
95  // Update the desktop file which is used for mount/unmount (icon change)
96  kDebug(7015) << " mount finished : updating " << m_desktopFile;
97  KUrl dfURL;
98  dfURL.setPath( m_desktopFile );
99  org::kde::KDirNotify::emitFilesChanged( QStringList() << dfURL.url() );
100  //KDirWatch::self()->setFileDirty( m_desktopFile );
101 
102  emit q->finished();
103  }
104  q->deleteLater();
105 }
106 
107 class KAutoUnmountPrivate
108 {
109 public:
110  KAutoUnmountPrivate( KAutoUnmount *qq, const QString & _mountpoint, const QString & _desktopFile )
111  : q(qq), m_desktopFile( _desktopFile ), m_mountpoint( _mountpoint )
112  {}
113  KAutoUnmount *q;
114  QString m_desktopFile;
115  QString m_mountpoint;
116 
117  void slotResult( KJob * job );
118 };
119 
120 KAutoUnmount::KAutoUnmount( const QString & _mountpoint, const QString & _desktopFile )
121  : d( new KAutoUnmountPrivate(this, _mountpoint, _desktopFile) )
122 {
123  KIO::Job * job = KIO::unmount( d->m_mountpoint );
124  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)) );
125 }
126 
127 void KAutoUnmountPrivate::slotResult( KJob * job )
128 {
129  if ( job->error() ) {
130  emit q->error();
131  job->uiDelegate()->showErrorMessage();
132  }
133  else
134  {
135  // Update the desktop file which is used for mount/unmount (icon change)
136  kDebug(7015) << "unmount finished : updating " << m_desktopFile;
137  KUrl dfURL;
138  dfURL.setPath( m_desktopFile );
139  org::kde::KDirNotify::emitFilesChanged( QStringList() << dfURL.url() );
140  //KDirWatch::self()->setFileDirty( m_desktopFile );
141 
142  // Notify about the new stuff in that dir, in case of opened windows showing it
143  // You may think we removed files, but this may have also readded some
144  // (if the mountpoint wasn't empty). The only possible behavior on FilesAdded
145  // is to relist the directory anyway.
146  KUrl mp( m_mountpoint );
147  org::kde::KDirNotify::emitFilesAdded( mp.url() );
148 
149  emit q->finished();
150  }
151 
152  q->deleteLater();
153 }
154 
155 KAutoUnmount::~KAutoUnmount()
156 {
157  delete d;
158 }
159 
160 #include "kautomount.moc"
KIO::unmount
SimpleJob * unmount(const QString &point, JobFlags flags=DefaultFlags)
Unmount filesystem.
Definition: job.cpp:762
KSharedPtr
Definition: kprotocolmanager.h:31
kdebug.h
KAutoUnmount::KAutoUnmount
KAutoUnmount(const QString &mountpoint, const QString &desktopFile)
Unmounts a device.
Definition: kautomount.cpp:120
QByteArray
kmountpoint.h
KMountPoint::currentMountPoints
static List currentMountPoints(DetailsNeededFlags infoNeeded=BasicInfoNeeded)
kdirwatch.h
KAutoMount
This class implements synchronous mounting of devices, as well as showing a file-manager window after...
Definition: kautomount.h:45
kdirnotify.h
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
OrgKdeKDirNotifyInterface::emitFilesAdded
static void emitFilesAdded(const QString &directory)
Definition: kdirnotify.cpp:47
KUrl
KUrl::setPath
void setPath(const QString &path)
KIO::mount
SimpleJob * mount(bool ro, const QByteArray &fstype, const QString &dev, const QString &point, JobFlags flags=DefaultFlags)
Mount filesystem.
Definition: job.cpp:751
KAutoUnmount
This class implements synchronous unmounting of devices, It is a wrapper around the asychronous KIO::...
Definition: kautomount.h:85
QString
QStringList
jobuidelegate.h
KAutoMount::KAutoMount
KAutoMount(bool readonly, const QByteArray &format, const QString &device, const QString &mountpoint, const QString &desktopFile, bool show_filemanager_window=true)
Mounts a device.
Definition: kautomount.cpp:52
job.h
krun.h
KRun::runUrl
static bool runUrl(const KUrl &url, const QString &mimetype, QWidget *window, bool tempFile=false, bool runExecutables=true, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
Open the given URL.
Definition: krun.cpp:122
KIO::Job
The base class for all jobs.
Definition: jobclasses.h:94
OrgKdeKDirNotifyInterface::emitFilesChanged
static void emitFilesChanged(const QStringList &fileList)
Definition: kdirnotify.cpp:52
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KMountPoint::List
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
kautomount.h
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal