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

KIO

  • 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 #include <sys/mount.h>
28 
29 /***********************************************************************
30  *
31  * Utility classes
32  *
33  ***********************************************************************/
34 
35 class KAutoMountPrivate
36 {
37 public:
38  KAutoMountPrivate(KAutoMount *qq, const QString &device, const QString& mountPoint,
39  const QString &desktopFile, bool showFileManagerWindow)
40  : q(qq), m_strDevice(device), m_desktopFile(desktopFile), m_mountPoint(mountPoint),
41  m_bShowFilemanagerWindow(showFileManagerWindow)
42  { }
43 
44  KAutoMount *q;
45  QString m_strDevice;
46  QString m_desktopFile;
47  QString m_mountPoint;
48  bool m_bShowFilemanagerWindow;
49 
50  void slotResult( KJob * );
51 };
52 
53 KAutoMount::KAutoMount( bool _readonly, const QByteArray& _format, const QString& _device,
54  const QString& _mountpoint, const QString & _desktopFile,
55  bool _show_filemanager_window )
56  : d(new KAutoMountPrivate(this, _device, _mountpoint, _desktopFile, _show_filemanager_window))
57 {
58  KIO::Job* job = KIO::mount( _readonly, _format, _device, _mountpoint );
59  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)) );
60 }
61 
62 KAutoMount::~KAutoMount()
63 {
64  delete d;
65 }
66 
67 void KAutoMountPrivate::slotResult( KJob * job )
68 {
69  if ( job->error() ) {
70  emit q->error();
71  job->uiDelegate()->showErrorMessage();
72  } else {
73  const KMountPoint::List mountPoints (KMountPoint::currentMountPoints());
74  KMountPoint::Ptr mp = mountPoints.findByDevice(m_strDevice);
75  // Mounting devices using "LABEL=" or "UUID=" will fail if we look for
76  // the device using only its real name since /etc/mtab will never contain
77  // the LABEL or UUID entries. Hence, we check using the mount point below
78  // when device name lookup fails. #247235
79  if (!mp) {
80  mp = mountPoints.findByPath(m_mountPoint);
81  }
82 
83  if (!mp) {
84  kWarning(7015) << m_strDevice << "was correctly mounted, but findByDevice() didn't find it."
85  << "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";
86  } else {
87  KUrl url(mp->mountPoint());
88  //kDebug(7015) << "KAutoMount: m_strDevice=" << m_strDevice << " -> mountpoint=" << mountpoint;
89  if ( m_bShowFilemanagerWindow ) {
90  KRun::runUrl( url, "inode/directory", 0 /*TODO - window*/ );
91  }
92  // Notify about the new stuff in that dir, in case of opened windows showing it
93  org::kde::KDirNotify::emitFilesAdded( url.url() );
94  }
95 
96  // Update the desktop file which is used for mount/unmount (icon change)
97  kDebug(7015) << " mount finished : updating " << m_desktopFile;
98  KUrl dfURL;
99  dfURL.setPath( m_desktopFile );
100  org::kde::KDirNotify::emitFilesChanged( QStringList() << dfURL.url() );
101  //KDirWatch::self()->setFileDirty( m_desktopFile );
102 
103  emit q->finished();
104  }
105  q->deleteLater();
106 }
107 
108 class KAutoUnmountPrivate
109 {
110 public:
111  KAutoUnmountPrivate( KAutoUnmount *qq, const QString & _mountpoint, const QString & _desktopFile )
112  : q(qq), m_desktopFile( _desktopFile ), m_mountpoint( _mountpoint )
113  {}
114  KAutoUnmount *q;
115  QString m_desktopFile;
116  QString m_mountpoint;
117 
118  void slotResult( KJob * job );
119 };
120 
121 KAutoUnmount::KAutoUnmount( const QString & _mountpoint, const QString & _desktopFile )
122  : d( new KAutoUnmountPrivate(this, _mountpoint, _desktopFile) )
123 {
124  KIO::Job * job = KIO::unmount( d->m_mountpoint );
125  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)) );
126 }
127 
128 void KAutoUnmountPrivate::slotResult( KJob * job )
129 {
130  if ( job->error() ) {
131  emit q->error();
132  job->uiDelegate()->showErrorMessage();
133  }
134  else
135  {
136  // Update the desktop file which is used for mount/unmount (icon change)
137  kDebug(7015) << "unmount finished : updating " << m_desktopFile;
138  KUrl dfURL;
139  dfURL.setPath( m_desktopFile );
140  org::kde::KDirNotify::emitFilesChanged( QStringList() << dfURL.url() );
141  //KDirWatch::self()->setFileDirty( m_desktopFile );
142 
143  // Notify about the new stuff in that dir, in case of opened windows showing it
144  // You may think we removed files, but this may have also readded some
145  // (if the mountpoint wasn't empty). The only possible behavior on FilesAdded
146  // is to relist the directory anyway.
147  KUrl mp( m_mountpoint );
148  org::kde::KDirNotify::emitFilesAdded( mp.url() );
149 
150  emit q->finished();
151  }
152 
153  q->deleteLater();
154 }
155 
156 KAutoUnmount::~KAutoUnmount()
157 {
158  delete d;
159 }
160 
161 #include "kautomount.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Wed Mar 20 2013 07:19:32 by doxygen 1.8.3.1 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-4.10.1 API Reference

Skip menu "kdelibs-4.10.1 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
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