diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2019-08-24 18:25:55 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2020-10-17 10:48:28 +0800 |
commit | d34f23f403e82f352e4c5d4e20966bcba2bec8c6 (patch) | |
tree | a1c02a3f85d2cf018f279bca095d5012702701e5 /tdeioslave/media/libmediacommon | |
parent | ebc4784c4fddeb307f4bc2ab83b4189312f24f3b (diff) | |
download | tdebase-d34f23f403e82f352e4c5d4e20966bcba2bec8c6.tar.gz tdebase-d34f23f403e82f352e4c5d4e20966bcba2bec8c6.zip |
tdeioslave media: clean up code related to medium mountable state in preparation for further work.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdeioslave/media/libmediacommon')
-rw-r--r-- | tdeioslave/media/libmediacommon/medium.cpp | 202 | ||||
-rw-r--r-- | tdeioslave/media/libmediacommon/medium.h | 96 |
2 files changed, 137 insertions, 161 deletions
diff --git a/tdeioslave/media/libmediacommon/medium.cpp b/tdeioslave/media/libmediacommon/medium.cpp index 77e32ba0f..7ded6f0f1 100644 --- a/tdeioslave/media/libmediacommon/medium.cpp +++ b/tdeioslave/media/libmediacommon/medium.cpp @@ -23,68 +23,57 @@ const TQString Medium::SEPARATOR = "---"; +void Medium::initMedium() +{ + m_properties.clear(); + m_properties += TQString::null; // ID + m_properties += TQString::null; // UUID + m_properties += TQString::null; // NAME + m_properties += TQString::null; // LABEL + m_properties += TQString::null; // USER_LABEL + m_properties += "false"; // MOUNTABLE + m_properties += TQString::null; // DEVICE_NODE + m_properties += TQString::null; // MOUNT_POINT + m_properties += TQString::null; // FS_TYPE + m_properties += "false"; // MOUNTED + m_properties += TQString::null; // BASE_URL + m_properties += TQString::null; // MIME_TYPE + m_properties += TQString::null; // ICON_NAME + m_properties += "false"; // ENCRYPTED + m_properties += TQString::null; // CLEAR_DEVICE_UDI + m_properties += "false"; // HIDDEN + m_properties += "false"; // SOFT_HIDDEN +} + Medium::Medium(const TQString id, TQString uuid, const TQString name) { - m_properties+= id; /* ID */ - m_properties+= uuid; /* UUID */ - m_properties+= name; /* NAME */ - m_properties+= name; /* LABEL */ - m_properties+= TQString::null; /* USER_LABEL */ - - m_properties+= "false"; /* MOUNTABLE */ - m_properties+= TQString::null; /* DEVICE_NODE */ - m_properties+= TQString::null; /* MOUNT_POINT */ - m_properties+= TQString::null; /* FS_TYPE */ - m_properties+= "false"; /* MOUNTED */ - m_properties+= TQString::null; /* BASE_URL */ - m_properties+= TQString::null; /* MIME_TYPE */ - m_properties+= TQString::null; /* ICON_NAME */ - m_properties+= "false"; /* ENCRYPTED */ - m_properties+= TQString::null; /* CLEAR_DEVICE_UDI */ - m_properties+= "false"; /* HIDDEN */ - m_properties+= "false"; /* SOFT_HIDDEN */ - - loadUserLabel(); - - m_halmounted = false; + initMedium(); + if (!id.isEmpty() && !uuid.isEmpty()) + { + m_properties[ID] = id; + m_properties[UUID] = uuid; + m_properties[NAME] = name; + m_properties[LABEL] = name; + loadUserLabel(); + } } Medium::Medium() { - m_properties+= TQString::null; /* ID */ - m_properties+= TQString::null; /* UUID */ - m_properties+= TQString::null; /* NAME */ - m_properties+= TQString::null; /* LABEL */ - m_properties+= TQString::null; /* USER_LABEL */ - - m_properties+= TQString::null; /* MOUNTABLE */ - m_properties+= TQString::null; /* DEVICE_NODE */ - m_properties+= TQString::null; /* MOUNT_POINT */ - m_properties+= TQString::null; /* FS_TYPE */ - m_properties+= TQString::null; /* MOUNTED */ - m_properties+= TQString::null; /* BASE_URL */ - m_properties+= TQString::null; /* MIME_TYPE */ - m_properties+= TQString::null; /* ICON_NAME */ - m_properties+= TQString::null; /* ENCRYPTED */ - m_properties+= TQString::null; /* CLEAR_DEVICE_UDI */ - m_properties+= "false"; /* HIDDEN */ - m_properties+= "false"; /* SOFT_HIDDEN */ - - m_halmounted = false; + initMedium(); } const Medium Medium::create(const TQStringList &properties) { Medium m; - if ( properties.size() >= PROPERTIES_COUNT ) + if (properties.size() >= PROPERTIES_COUNT) { m.m_properties[ID] = properties[ID]; m.m_properties[UUID] = properties[UUID]; m.m_properties[NAME] = properties[NAME]; m.m_properties[LABEL] = properties[LABEL]; m.m_properties[USER_LABEL] = properties[USER_LABEL]; - m.m_properties[MOUNTABLE] = properties[MOUNTABLE]; m.m_properties[DEVICE_NODE] = properties[DEVICE_NODE]; m.m_properties[MOUNT_POINT] = properties[MOUNT_POINT]; @@ -106,13 +95,12 @@ Medium::MList Medium::createList(const TQStringList &properties) { MList l; - if ( properties.size() % (PROPERTIES_COUNT+1) == 0) + if (properties.size() % (PROPERTIES_COUNT+1) == 0) { - int media_count = properties.size()/(PROPERTIES_COUNT+1); - + int media_count = properties.size() / (PROPERTIES_COUNT + 1); TQStringList props = properties; - for(int i=0; i<media_count; i++) + for (int i=0; i < media_count; i++) { const Medium m = create(props); l.append(m); @@ -127,7 +115,6 @@ Medium::MList Medium::createList(const TQStringList &properties) return l; } - void Medium::setName(const TQString &name) { m_properties[NAME] = name; @@ -138,35 +125,22 @@ void Medium::setLabel(const TQString &label) m_properties[LABEL] = label; } -void Medium::setEncrypted(bool state) -{ - m_properties[ENCRYPTED] = ( state ? "true" : "false" ); -} - -void Medium::setHidden(bool state) -{ - m_properties[HIDDEN] = ( state ? "true" : "false" ); -} - -void Medium::setSoftHidden(bool state) -{ - m_properties[SOFT_HIDDEN] = ( state ? "true" : "false" ); -} - void Medium::setUserLabel(const TQString &label) { TDEConfig cfg("mediamanagerrc"); cfg.setGroup("UserLabels"); TQString entry_name = m_properties[UUID]; - - if ( label.isNull() ) - { - cfg.deleteEntry(entry_name); - } - else + if (!entry_name.isEmpty()) { - cfg.writeEntry(entry_name, label); + if (label.isEmpty()) + { + cfg.deleteEntry(entry_name); + } + else + { + cfg.writeEntry(entry_name, label); + } } m_properties[USER_LABEL] = label; @@ -178,10 +152,9 @@ void Medium::loadUserLabel() cfg.setGroup("UserLabels"); TQString entry_name = m_properties[UUID]; - - if ( cfg.hasKey(entry_name) ) + if (!entry_name.isEmpty()) { - m_properties[USER_LABEL] = cfg.readEntry(entry_name); + m_properties[USER_LABEL] = cfg.readEntry(entry_name, TQString::null); } else { @@ -189,48 +162,38 @@ void Medium::loadUserLabel() } } - -bool Medium::mountableState(bool mounted) +void Medium::setMountable(bool mountable) { - if ( m_properties[DEVICE_NODE].isEmpty() - || ( mounted && m_properties[MOUNT_POINT].isEmpty() ) ) + m_properties[MOUNTABLE] = mountable ? "true" : "false"; + if (!mountable) { - return false; + setMountPoint(TQString::null); + setMounted(false); } - - m_properties[MOUNTABLE] = "true"; - m_properties[MOUNTED] = ( mounted ? "true" : "false" ); - - return true; } -void Medium::mountableState(const TQString &deviceNode, - const TQString &mountPoint, - const TQString &fsType, bool mounted) +void Medium::setDeviceNode(const TQString &deviceNode) { - m_properties[MOUNTABLE] = "true"; m_properties[DEVICE_NODE] = deviceNode; - m_properties[MOUNT_POINT] = mountPoint; - m_properties[FS_TYPE] = fsType; - m_properties[MOUNTED] = ( mounted ? "true" : "false" ); } -void Medium::mountableState(const TQString &deviceNode, - const TQString &clearDeviceUdi, - const TQString &mountPoint, - const TQString &fsType, bool mounted) +void Medium::setMountPoint(const TQString &mountPoint) { - m_properties[MOUNTABLE] = "true"; - m_properties[DEVICE_NODE] = deviceNode; - m_properties[CLEAR_DEVICE_UDI] = clearDeviceUdi; m_properties[MOUNT_POINT] = mountPoint; +} + +void Medium::setFsType(const TQString &fsType) +{ m_properties[FS_TYPE] = fsType; - m_properties[MOUNTED] = ( mounted ? "true" : "false" ); } -void Medium::unmountableState(const TQString &baseURL) +void Medium::setMounted(bool mounted) +{ + m_properties[MOUNTED] = mounted ? "true" : "false"; +} + +void Medium::setBaseURL(const TQString &baseURL) { - m_properties[MOUNTABLE] = "false"; m_properties[BASE_URL] = baseURL; } @@ -244,6 +207,26 @@ void Medium::setIconName(const TQString &iconName) m_properties[ICON_NAME] = iconName; } +void Medium::setEncrypted(bool state) +{ + m_properties[ENCRYPTED] = ( state ? "true" : "false" ); +} + +void Medium::setClearDeviceUdi(const TQString &clearDeviceUdi) +{ + m_properties[CLEAR_DEVICE_UDI] = clearDeviceUdi; +} + +void Medium::setHidden(bool state) +{ + m_properties[HIDDEN] = ( state ? "true" : "false" ); +} + +void Medium::setSoftHidden(bool state) +{ + m_properties[SOFT_HIDDEN] = ( state ? "true" : "false" ); +} + bool Medium::needMounting() const { return isMountable() && !isMounted(); @@ -256,21 +239,20 @@ bool Medium::needDecryption() const KURL Medium::prettyBaseURL() const { - if ( !baseURL().isEmpty() ) - return baseURL(); + if (!baseURL().isEmpty()) + { + return baseURL(); + } - return KURL( mountPoint() ); + return KURL(mountPoint()); } TQString Medium::prettyLabel() const { - if ( !userLabel().isEmpty() ) + if (!userLabel().isEmpty()) { return userLabel(); } - else - { - return label(); - } -} + return label(); +} diff --git a/tdeioslave/media/libmediacommon/medium.h b/tdeioslave/media/libmediacommon/medium.h index bf465fd09..7e7f2b04a 100644 --- a/tdeioslave/media/libmediacommon/medium.h +++ b/tdeioslave/media/libmediacommon/medium.h @@ -29,24 +29,24 @@ class Medium public: typedef TQValueList<Medium> MList; - static const uint ID = 0; - static const uint UUID = 1; - static const uint NAME = 2; - static const uint LABEL = 3; - static const uint USER_LABEL = 4; - static const uint MOUNTABLE = 5; - static const uint DEVICE_NODE = 6; - static const uint MOUNT_POINT = 7; - static const uint FS_TYPE = 8; - static const uint MOUNTED = 9; - static const uint BASE_URL = 10; - static const uint MIME_TYPE = 11; - static const uint ICON_NAME = 12; - static const uint ENCRYPTED = 13; - static const uint CLEAR_DEVICE_UDI = 14; - static const uint HIDDEN = 15; - static const uint SOFT_HIDDEN = 16; - static const uint PROPERTIES_COUNT = 17; + static const uint ID = 0; + static const uint UUID = 1; + static const uint NAME = 2; + static const uint LABEL = 3; + static const uint USER_LABEL = 4; + static const uint MOUNTABLE = 5; + static const uint DEVICE_NODE = 6; + static const uint MOUNT_POINT = 7; + static const uint FS_TYPE = 8; + static const uint MOUNTED = 9; + static const uint BASE_URL = 10; + static const uint MIME_TYPE = 11; + static const uint ICON_NAME = 12; + static const uint ENCRYPTED = 13; + static const uint CLEAR_DEVICE_UDI = 14; + static const uint HIDDEN = 15; + static const uint SOFT_HIDDEN = 16; + static const uint PROPERTIES_COUNT = 17; static const TQString SEPARATOR; Medium(const TQString id, TQString uuid, const TQString name); @@ -60,18 +60,18 @@ public: TQString name() const { return m_properties[NAME]; } TQString label() const { return m_properties[LABEL]; } TQString userLabel() const { return m_properties[USER_LABEL]; } - bool isMountable() const { return m_properties[MOUNTABLE]=="true"; } + bool isMountable() const { return m_properties[MOUNTABLE]=="true"; } TQString deviceNode() const { return m_properties[DEVICE_NODE]; } TQString mountPoint() const { return m_properties[MOUNT_POINT]; } TQString fsType() const { return m_properties[FS_TYPE]; } - bool isMounted() const { return m_properties[MOUNTED]=="true"; } + bool isMounted() const { return m_properties[MOUNTED]=="true"; } TQString baseURL() const { return m_properties[BASE_URL]; } TQString mimeType() const { return m_properties[MIME_TYPE]; } TQString iconName() const { return m_properties[ICON_NAME]; } - bool isEncrypted() const { return m_properties[ENCRYPTED]=="true"; }; + bool isEncrypted() const { return m_properties[ENCRYPTED]=="true"; }; TQString clearDeviceUdi() const { return m_properties[CLEAR_DEVICE_UDI]; }; - bool hidden() const { return m_properties[HIDDEN]=="true"; }; - bool softHidden() const { return m_properties[SOFT_HIDDEN]=="true"; }; + bool hidden() const { return m_properties[HIDDEN]=="true"; }; + bool softHidden() const { return m_properties[SOFT_HIDDEN]=="true"; }; bool needMounting() const; bool needDecryption() const; @@ -81,50 +81,44 @@ public: void setName(const TQString &name); void setLabel(const TQString &label); void setUserLabel(const TQString &label); + void setMountable(bool mountable); + void setDeviceNode(const TQString &deviceNode); + void setMountPoint(const TQString &mountPoint); + void setFsType(const TQString &fsType); + void setMounted(bool mounted); + void setBaseURL(const TQString &baseURL); + void setMimeType(const TQString &mimeType); + void setIconName(const TQString &iconName); void setEncrypted(bool state); + void setClearDeviceUdi(const TQString &clearDeviceUdi); void setHidden(bool state); void setSoftHidden(bool state); - bool mountableState(bool mounted); - void mountableState(const TQString &deviceNode, - const TQString &mountPoint, - const TQString &fsType, bool mounted); - void mountableState(const TQString &deviceNode, - const TQString &clearDeviceUdi, - const TQString &mountPoint, - const TQString &fsType, bool mounted); - void unmountableState(const TQString &baseURL = TQString::null); - - void setMimeType(const TQString &mimeType); - void setIconName(const TQString &iconName); - void setHalMounted(bool flag) const { m_halmounted = flag; } - bool halMounted() const { return m_halmounted; } - -//private: Medium(); private: + void initMedium(); void loadUserLabel(); TQStringList m_properties; - mutable bool m_halmounted; -friend class TQValueListNode<const Medium>; + friend class TQValueListNode<const Medium>; }; namespace MediaManagerUtils { - static inline TQMap<TQString,TQString> splitOptions(const TQStringList & options) - { - TQMap<TQString,TQString> valids; - - for (TQStringList::ConstIterator it = options.begin(); it != options.end(); ++it) + static inline TQMap<TQString,TQString> splitOptions(const TQStringList &options) { - TQString key = (*it).left((*it).find('=')); - TQString value = (*it).mid((*it).find('=') + 1); - valids[key] = value; + TQMap<TQString,TQString> valids; + + for (TQStringList::ConstIterator it = options.begin(); it != options.end(); ++it) + { + int pos = (*it).find('='); + TQString key = (*it).left(pos); + TQString value = (*it).mid(pos + 1); + valids[key] = value; + } + return valids; } - return valids; - } } #endif |