2 * This file is part of QMAFW
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). All rights
7 * Contact: Visa Smolander <visa.smolander@nokia.com>
9 * This software, including documentation, is protected by copyright controlled
10 * by Nokia Corporation. All rights are reserved. Copying, including
11 * reproducing, storing, adapting or translating, any or all of this material
12 * requires the prior written consent of Nokia Corporation. This material also
13 * contains confidential information which may not be disclosed to others
14 * without the prior written consent of Nokia.
18 #include "MafwMmcMonitor.h"
22 #include <usb_moded-dbus.h>
23 #include <QDBusConnection>
25 const QString MafwMmcMonitor::MMC_URI_PREFIX="file:///home/user/MyDocs";
27 MafwMmcMonitor::MafwMmcMonitor(QObject* parent) : QObject(parent), m_mounted(false)
29 m_gVolMonitor=g_volume_monitor_get();
31 g_signal_connect(m_gVolMonitor, "mount-removed",
32 G_CALLBACK(unmountEvent), this);
33 g_signal_connect(m_gVolMonitor, "mount-added",
34 G_CALLBACK(mountEvent), this);
36 GList* mounts=g_volume_monitor_get_mounts(m_gVolMonitor);
39 for( guint i=0; i<g_list_length(mounts); i++ )
41 GMount* m=(GMount*)g_list_nth_data(mounts, i);
51 QDBusConnection conn = QDBusConnection::systemBus();
52 if( !conn.connect(USB_MODE_SERVICE,
57 SLOT(preUnmountEvent(QString))) )
59 qCritical() << "MafwGstRenderer could not connect to USB pre unmount signal!";
63 MafwMmcMonitor::~MafwMmcMonitor()
65 g_object_unref(m_gVolMonitor);
67 QDBusConnection conn = QDBusConnection::systemBus();
68 conn.disconnect(USB_MODE_SERVICE,
73 SLOT(preUnmountEvent(QString)));
76 bool MafwMmcMonitor::isMounted()
81 void MafwMmcMonitor::preUnmountEvent(const QString &state)
83 //this slot will receive other information from usb_moded besides pre-unmount
84 if( state == USB_PRE_UNMOUNT )
86 qDebug() << "preUnmountEvent";
87 // This assumes that preunmount always affects MyDocs
92 void MafwMmcMonitor::unmountEvent(GVolumeMonitor * mon,
98 qDebug() << "unmountEvent";
100 if( isMyDocs(mount) )
102 MafwMmcMonitor* self=static_cast<MafwMmcMonitor*>(userData);
103 self->m_mounted = false;
107 void MafwMmcMonitor::mountEvent(GVolumeMonitor * mon,
113 qDebug() << "mountEvent";
115 if( isMyDocs(mount) )
117 MafwMmcMonitor* self=static_cast<MafwMmcMonitor*>(userData);
118 self->m_mounted = true;
122 bool MafwMmcMonitor::isMyDocs(GMount* mount)
126 root = g_mount_get_root(mount);
129 char* uri=g_file_get_uri(root);
130 if( uri && MMC_URI_PREFIX.compare(uri)==0 )
134 qDebug() << "MafwMmcMonitor::isMyDocs" << uri << isIt;
136 g_object_unref(root);