summaryrefslogtreecommitdiffstats
path: root/tdeioslave/media/libmediacommon/medium.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tdeioslave/media/libmediacommon/medium.cpp')
-rw-r--r--tdeioslave/media/libmediacommon/medium.cpp225
1 files changed, 111 insertions, 114 deletions
diff --git a/tdeioslave/media/libmediacommon/medium.cpp b/tdeioslave/media/libmediacommon/medium.cpp
index 77e32ba0f..797c409b4 100644
--- a/tdeioslave/media/libmediacommon/medium.cpp
+++ b/tdeioslave/media/libmediacommon/medium.cpp
@@ -23,68 +23,58 @@
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
+ m_properties += "false"; // LOCKED
+}
+
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];
@@ -97,6 +87,7 @@ const Medium Medium::create(const TQStringList &properties)
m.m_properties[CLEAR_DEVICE_UDI] = properties[CLEAR_DEVICE_UDI];
m.m_properties[HIDDEN] = properties[HIDDEN];
m.m_properties[SOFT_HIDDEN] = properties[SOFT_HIDDEN];
+ m.m_properties[LOCKED] = properties[LOCKED];
}
return m;
@@ -106,13 +97,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 +117,6 @@ Medium::MList Medium::createList(const TQStringList &properties)
return l;
}
-
void Medium::setName(const TQString &name)
{
m_properties[NAME] = name;
@@ -138,35 +127,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 +154,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 +164,52 @@ 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" );
+void Medium::setDeviceNode(const TQString &deviceNode)
+{
+ m_properties[DEVICE_NODE] = deviceNode;
+}
- return true;
+void Medium::setMountPoint(const TQString &mountPoint)
+{
+ if (isMountable())
+ {
+ m_properties[MOUNT_POINT] = mountPoint;
+ }
+ else
+ {
+ m_properties[MOUNT_POINT] = TQString::null;
+ }
}
-void Medium::mountableState(const TQString &deviceNode,
- const TQString &mountPoint,
- const TQString &fsType, bool mounted)
+void Medium::setFsType(const TQString &fsType)
{
- 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::setMounted(bool mounted)
{
- m_properties[MOUNTABLE] = "true";
- m_properties[DEVICE_NODE] = deviceNode;
- m_properties[CLEAR_DEVICE_UDI] = clearDeviceUdi;
- m_properties[MOUNT_POINT] = mountPoint;
- m_properties[FS_TYPE] = fsType;
- m_properties[MOUNTED] = ( mounted ? "true" : "false" );
+ if (isMountable())
+ {
+ m_properties[MOUNTED] = mounted ? "true" : "false";
+ }
+ else
+ {
+ m_properties[MOUNTED] = "false";
+ }
}
-void Medium::unmountableState(const TQString &baseURL)
+void Medium::setBaseURL(const TQString &baseURL)
{
- m_properties[MOUNTABLE] = "false";
m_properties[BASE_URL] = baseURL;
}
@@ -244,33 +223,51 @@ void Medium::setIconName(const TQString &iconName)
m_properties[ICON_NAME] = iconName;
}
-bool Medium::needMounting() const
+void Medium::setEncrypted(bool encrypted)
+{
+ m_properties[ENCRYPTED] = encrypted ? "true" : "false";
+ if (!encrypted)
+ {
+ setLocked(false);
+ }
+}
+
+void Medium::setClearDeviceUdi(const TQString &clearDeviceUdi)
{
- return isMountable() && !isMounted();
+ m_properties[CLEAR_DEVICE_UDI] = clearDeviceUdi;
}
-bool Medium::needDecryption() const
+void Medium::setHidden(bool state)
{
- return isEncrypted() && clearDeviceUdi().isEmpty();
+ m_properties[HIDDEN] = state ? "true" : "false";
+}
+
+void Medium::setSoftHidden(bool state)
+{
+ m_properties[SOFT_HIDDEN] = state ? "true" : "false";
+}
+
+void Medium::setLocked(bool locked)
+{
+ m_properties[LOCKED] = locked ? "true" : "false";
}
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();
+}