You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
269 lines
6.7 KiB
269 lines
6.7 KiB
15 years ago
|
/* This file is part of the KDE Project
|
||
|
Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "medium.h"
|
||
|
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <klocale.h>
|
||
|
|
||
14 years ago
|
const TQString Medium::SEPARATOR = "---";
|
||
15 years ago
|
|
||
12 years ago
|
Medium::Medium(const TQString id, TQString uuid, const TQString name)
|
||
15 years ago
|
{
|
||
|
m_properties+= id; /* ID */
|
||
12 years ago
|
m_properties+= uuid; /* UUID */
|
||
15 years ago
|
m_properties+= name; /* NAME */
|
||
|
m_properties+= name; /* LABEL */
|
||
14 years ago
|
m_properties+= TQString::null; /* USER_LABEL */
|
||
15 years ago
|
|
||
|
m_properties+= "false"; /* MOUNTABLE */
|
||
14 years ago
|
m_properties+= TQString::null; /* DEVICE_NODE */
|
||
|
m_properties+= TQString::null; /* MOUNT_POINT */
|
||
|
m_properties+= TQString::null; /* FS_TYPE */
|
||
15 years ago
|
m_properties+= "false"; /* MOUNTED */
|
||
14 years ago
|
m_properties+= TQString::null; /* BASE_URL */
|
||
|
m_properties+= TQString::null; /* MIME_TYPE */
|
||
|
m_properties+= TQString::null; /* ICON_NAME */
|
||
15 years ago
|
m_properties+= "false"; /* ENCRYPTED */
|
||
14 years ago
|
m_properties+= TQString::null; /* CLEAR_DEVICE_UDI */
|
||
13 years ago
|
m_properties+= "false"; /* HIDDEN */
|
||
15 years ago
|
|
||
|
loadUserLabel();
|
||
|
|
||
|
m_halmounted = false;
|
||
|
}
|
||
|
|
||
|
Medium::Medium()
|
||
|
{
|
||
14 years ago
|
m_properties+= TQString::null; /* ID */
|
||
12 years ago
|
m_properties+= TQString::null; /* UUID */
|
||
14 years ago
|
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 */
|
||
13 years ago
|
m_properties+= "false"; /* HIDDEN */
|
||
15 years ago
|
|
||
|
m_halmounted = false;
|
||
|
}
|
||
|
|
||
14 years ago
|
const Medium Medium::create(const TQStringList &properties)
|
||
15 years ago
|
{
|
||
|
Medium m;
|
||
|
|
||
|
if ( properties.size() >= PROPERTIES_COUNT )
|
||
|
{
|
||
|
m.m_properties[ID] = properties[ID];
|
||
12 years ago
|
m.m_properties[UUID] = properties[UUID];
|
||
15 years ago
|
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];
|
||
|
m.m_properties[FS_TYPE] = properties[FS_TYPE];
|
||
|
m.m_properties[MOUNTED] = properties[MOUNTED];
|
||
|
m.m_properties[BASE_URL] = properties[BASE_URL];
|
||
|
m.m_properties[MIME_TYPE] = properties[MIME_TYPE];
|
||
|
m.m_properties[ICON_NAME] = properties[ICON_NAME];
|
||
15 years ago
|
m.m_properties[ENCRYPTED] = properties[ENCRYPTED];
|
||
|
m.m_properties[CLEAR_DEVICE_UDI] = properties[CLEAR_DEVICE_UDI];
|
||
13 years ago
|
m.m_properties[HIDDEN] = properties[HIDDEN];
|
||
15 years ago
|
}
|
||
|
|
||
|
return m;
|
||
|
}
|
||
|
|
||
14 years ago
|
Medium::MList Medium::createList(const TQStringList &properties)
|
||
15 years ago
|
{
|
||
14 years ago
|
MList l;
|
||
15 years ago
|
|
||
|
if ( properties.size() % (PROPERTIES_COUNT+1) == 0)
|
||
|
{
|
||
|
int media_count = properties.size()/(PROPERTIES_COUNT+1);
|
||
|
|
||
14 years ago
|
TQStringList props = properties;
|
||
15 years ago
|
|
||
|
for(int i=0; i<media_count; i++)
|
||
|
{
|
||
|
const Medium m = create(props);
|
||
|
l.append(m);
|
||
|
|
||
14 years ago
|
TQStringList::iterator first = props.begin();
|
||
13 years ago
|
TQStringList::iterator last = props.find(SEPARATOR);
|
||
15 years ago
|
++last;
|
||
|
props.erase(first, last);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return l;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void Medium::setName(const TQString &name)
|
||
15 years ago
|
{
|
||
|
m_properties[NAME] = name;
|
||
|
}
|
||
|
|
||
14 years ago
|
void Medium::setLabel(const TQString &label)
|
||
15 years ago
|
{
|
||
|
m_properties[LABEL] = label;
|
||
|
}
|
||
|
|
||
15 years ago
|
void Medium::setEncrypted(bool state)
|
||
|
{
|
||
|
m_properties[ENCRYPTED] = ( state ? "true" : "false" );
|
||
|
}
|
||
|
|
||
13 years ago
|
void Medium::setHidden(bool state)
|
||
|
{
|
||
|
m_properties[HIDDEN] = ( state ? "true" : "false" );
|
||
|
}
|
||
|
|
||
14 years ago
|
void Medium::setUserLabel(const TQString &label)
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEConfig cfg("mediamanagerrc");
|
||
15 years ago
|
cfg.setGroup("UserLabels");
|
||
|
|
||
12 years ago
|
TQString entry_name = m_properties[UUID];
|
||
15 years ago
|
|
||
|
if ( label.isNull() )
|
||
|
{
|
||
|
cfg.deleteEntry(entry_name);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
cfg.writeEntry(entry_name, label);
|
||
|
}
|
||
|
|
||
|
m_properties[USER_LABEL] = label;
|
||
|
}
|
||
|
|
||
|
void Medium::loadUserLabel()
|
||
|
{
|
||
12 years ago
|
TDEConfig cfg("mediamanagerrc");
|
||
15 years ago
|
cfg.setGroup("UserLabels");
|
||
|
|
||
12 years ago
|
TQString entry_name = m_properties[UUID];
|
||
15 years ago
|
|
||
|
if ( cfg.hasKey(entry_name) )
|
||
|
{
|
||
|
m_properties[USER_LABEL] = cfg.readEntry(entry_name);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
m_properties[USER_LABEL] = TQString::null;
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
bool Medium::mountableState(bool mounted)
|
||
|
{
|
||
|
if ( m_properties[DEVICE_NODE].isEmpty()
|
||
|
|| ( mounted && m_properties[MOUNT_POINT].isEmpty() ) )
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
m_properties[MOUNTABLE] = "true";
|
||
|
m_properties[MOUNTED] = ( mounted ? "true" : "false" );
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
void Medium::mountableState(const TQString &deviceNode,
|
||
|
const TQString &mountPoint,
|
||
|
const TQString &fsType, bool mounted)
|
||
15 years ago
|
{
|
||
|
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" );
|
||
|
}
|
||
|
|
||
14 years ago
|
void Medium::mountableState(const TQString &deviceNode,
|
||
|
const TQString &clearDeviceUdi,
|
||
|
const TQString &mountPoint,
|
||
|
const TQString &fsType, bool mounted)
|
||
15 years ago
|
{
|
||
|
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" );
|
||
|
}
|
||
|
|
||
14 years ago
|
void Medium::unmountableState(const TQString &baseURL)
|
||
15 years ago
|
{
|
||
|
m_properties[MOUNTABLE] = "false";
|
||
|
m_properties[BASE_URL] = baseURL;
|
||
|
}
|
||
|
|
||
14 years ago
|
void Medium::setMimeType(const TQString &mimeType)
|
||
15 years ago
|
{
|
||
|
m_properties[MIME_TYPE] = mimeType;
|
||
|
}
|
||
|
|
||
14 years ago
|
void Medium::setIconName(const TQString &iconName)
|
||
15 years ago
|
{
|
||
|
m_properties[ICON_NAME] = iconName;
|
||
|
}
|
||
|
|
||
|
bool Medium::needMounting() const
|
||
|
{
|
||
|
return isMountable() && !isMounted();
|
||
|
}
|
||
|
|
||
15 years ago
|
bool Medium::needDecryption() const
|
||
|
{
|
||
|
return isEncrypted() && clearDeviceUdi().isEmpty();
|
||
|
}
|
||
|
|
||
15 years ago
|
KURL Medium::prettyBaseURL() const
|
||
|
{
|
||
|
if ( !baseURL().isEmpty() )
|
||
|
return baseURL();
|
||
|
|
||
|
return KURL( mountPoint() );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString Medium::prettyLabel() const
|
||
15 years ago
|
{
|
||
|
if ( !userLabel().isEmpty() )
|
||
|
{
|
||
|
return userLabel();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return label();
|
||
|
}
|
||
|
}
|
||
|
|