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

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