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.
304 lines
7.5 KiB
304 lines
7.5 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 "medialist.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
MediaList::MediaList()
|
||
|
{
|
||
|
kdDebug(1219) << "MediaList::MediaList()" << endl;
|
||
|
|
||
|
m_media.setAutoDelete(true);
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQPtrList<Medium> MediaList::list() const
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::list()" << endl;
|
||
|
|
||
|
return m_media;
|
||
|
}
|
||
|
|
||
15 years ago
|
const Medium *MediaList::findById(const TQString &id) const
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::findById(" << id << ")" << endl;
|
||
|
|
||
13 years ago
|
if ( !m_idMap.contains(id) ) return 0L;
|
||
15 years ago
|
|
||
|
return m_idMap[id];
|
||
|
}
|
||
|
|
||
15 years ago
|
const Medium *MediaList::findByName(const TQString &name) const
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::findByName(" << name << ")" << endl;
|
||
|
|
||
13 years ago
|
if ( !m_nameMap.contains(name) ) return 0L;
|
||
15 years ago
|
|
||
|
return m_nameMap[name];
|
||
|
}
|
||
|
|
||
15 years ago
|
const Medium *MediaList::findByClearUdi(const TQString &name)
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::findByClearUdi(" << name << ")" << endl;
|
||
|
|
||
|
Medium *medium;
|
||
|
for (medium = m_media.first(); medium; medium = m_media.next()) {
|
||
|
if (medium->clearDeviceUdi() == name) return medium;
|
||
|
}
|
||
|
|
||
|
return 0L;
|
||
|
}
|
||
|
|
||
15 years ago
|
|
||
15 years ago
|
TQString MediaList::addMedium(Medium *medium, bool allowNotification)
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::addMedium(@" << medium->id() << ")" << endl;
|
||
|
|
||
15 years ago
|
TQString id = medium->id();
|
||
13 years ago
|
if ( m_idMap.contains(id) ) return TQString::null;
|
||
15 years ago
|
|
||
|
m_media.append( medium );
|
||
|
m_idMap[id] = medium;
|
||
|
|
||
15 years ago
|
TQString name = medium->name();
|
||
13 years ago
|
if ( !m_nameMap.contains(name) )
|
||
15 years ago
|
{
|
||
|
m_nameMap[name] = medium;
|
||
|
|
||
|
kdDebug(1219) << "MediaList emits mediumAdded(" << id << ", "
|
||
|
<< name << ")" << endl;
|
||
|
emit mediumAdded(id, name, allowNotification);
|
||
|
|
||
|
return name;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString base_name = name+"_";
|
||
15 years ago
|
int i = 1;
|
||
|
|
||
13 years ago
|
while ( m_nameMap.contains(base_name+TQString::number(i)) )
|
||
15 years ago
|
{
|
||
|
i++;
|
||
|
}
|
||
|
|
||
15 years ago
|
name = base_name+TQString::number(i);
|
||
15 years ago
|
medium->setName(name);
|
||
|
m_nameMap[name] = medium;
|
||
|
|
||
|
kdDebug(1219) << "MediaList emits mediumAdded(" << id << ", "
|
||
|
<< name << ")" << endl;
|
||
|
emit mediumAdded(id, name, allowNotification);
|
||
|
return name;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool MediaList::removeMedium(const TQString &id, bool allowNotification)
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::removeMedium(" << id << ")" << endl;
|
||
|
|
||
13 years ago
|
if ( !m_idMap.contains(id) ) return false;
|
||
15 years ago
|
|
||
|
Medium *medium = m_idMap[id];
|
||
15 years ago
|
TQString name = medium->name();
|
||
15 years ago
|
|
||
|
m_idMap.remove(id);
|
||
|
m_nameMap.remove( medium->name() );
|
||
|
m_media.remove( medium );
|
||
|
|
||
|
emit mediumRemoved(id, name, allowNotification);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool MediaList::changeMediumState(const Medium &medium, bool allowNotification)
|
||
|
{
|
||
|
kdDebug(1219) << "MediaList::changeMediumState(const Medium &)" << endl;
|
||
|
|
||
13 years ago
|
if ( !m_idMap.contains(medium.id()) ) return false;
|
||
15 years ago
|
|
||
|
Medium *m = m_idMap[medium.id()];
|
||
|
|
||
|
if ( medium.isMountable() )
|
||
|
{
|
||
15 years ago
|
TQString device_node = medium.deviceNode();
|
||
|
TQString clear_device_udi = medium.clearDeviceUdi();
|
||
|
TQString mount_point = medium.mountPoint();
|
||
|
TQString fs_type = medium.fsType();
|
||
15 years ago
|
bool mounted = medium.isMounted();
|
||
|
|
||
15 years ago
|
m->mountableState( device_node, clear_device_udi, mount_point,
|
||
15 years ago
|
fs_type, mounted );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
m->unmountableState( medium.baseURL() );
|
||
|
}
|
||
|
|
||
|
|
||
|
if (!medium.mimeType().isEmpty())
|
||
|
{
|
||
|
m->setMimeType( medium.mimeType() );
|
||
|
}
|
||
|
|
||
|
if (!medium.iconName().isEmpty())
|
||
|
{
|
||
|
m->setIconName( medium.iconName() );
|
||
|
}
|
||
|
|
||
|
if (!medium.label().isEmpty())
|
||
|
{
|
||
|
m->setLabel( medium.label() );
|
||
|
}
|
||
|
|
||
13 years ago
|
m->setHidden(medium.hidden());
|
||
|
|
||
15 years ago
|
emit mediumStateChanged(m->id(), m->name(), !m->needMounting(), allowNotification);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool MediaList::changeMediumState(const TQString &id,
|
||
|
const TQString &baseURL,
|
||
15 years ago
|
bool allowNotification,
|
||
15 years ago
|
const TQString &mimeType,
|
||
|
const TQString &iconName,
|
||
|
const TQString &label)
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::changeMediumState(" << id << ", "
|
||
|
<< baseURL << ", " << mimeType << ", " << iconName << ")"
|
||
|
<< endl;
|
||
|
|
||
13 years ago
|
if ( !m_idMap.contains(id) ) return false;
|
||
15 years ago
|
|
||
|
Medium *medium = m_idMap[id];
|
||
|
|
||
|
medium->unmountableState( baseURL );
|
||
|
|
||
|
if (!mimeType.isEmpty())
|
||
|
{
|
||
|
medium->setMimeType( mimeType );
|
||
|
}
|
||
|
|
||
|
if (!iconName.isEmpty())
|
||
|
{
|
||
|
medium->setIconName( iconName );
|
||
|
}
|
||
|
|
||
|
if (!label.isEmpty())
|
||
|
{
|
||
|
medium->setLabel( label );
|
||
|
}
|
||
|
|
||
|
emit mediumStateChanged(id, medium->name(),
|
||
|
!medium->needMounting(),
|
||
|
allowNotification);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool MediaList::changeMediumState(const TQString &id,
|
||
|
const TQString &deviceNode,
|
||
|
const TQString &mountPoint,
|
||
|
const TQString &fsType, bool mounted,
|
||
15 years ago
|
bool allowNotification,
|
||
15 years ago
|
const TQString &mimeType,
|
||
|
const TQString &iconName,
|
||
|
const TQString &label)
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::changeMediumState(" << id << ", "
|
||
|
<< deviceNode << ", " << mountPoint << ", " << fsType << ", "
|
||
|
<< mounted << ", " << mimeType << ", " << iconName << ")"
|
||
|
<< endl;
|
||
|
|
||
13 years ago
|
if ( !m_idMap.contains(id) ) return false;
|
||
15 years ago
|
|
||
|
Medium *medium = m_idMap[id];
|
||
|
|
||
|
medium->mountableState( deviceNode, mountPoint, fsType, mounted );
|
||
|
|
||
|
if (!mimeType.isEmpty())
|
||
|
{
|
||
|
medium->setMimeType( mimeType );
|
||
|
}
|
||
|
|
||
|
if (!iconName.isEmpty())
|
||
|
{
|
||
|
medium->setIconName( iconName );
|
||
|
}
|
||
|
|
||
|
if (!label.isEmpty())
|
||
|
{
|
||
|
medium->setLabel( label );
|
||
|
}
|
||
|
|
||
|
emit mediumStateChanged(id, medium->name(),
|
||
|
!medium->needMounting(),
|
||
|
allowNotification);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool MediaList::changeMediumState(const TQString &id, bool mounted,
|
||
15 years ago
|
bool allowNotification,
|
||
15 years ago
|
const TQString &mimeType,
|
||
|
const TQString &iconName,
|
||
|
const TQString &label)
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::changeMediumState(" << id << ", "
|
||
|
<< mounted << ", " << mimeType << ", " << iconName << ")"
|
||
|
<< endl;
|
||
|
|
||
13 years ago
|
if ( !m_idMap.contains(id) ) return false;
|
||
15 years ago
|
|
||
|
Medium *medium = m_idMap[id];
|
||
|
|
||
|
if ( !medium->mountableState( mounted ) ) return false;
|
||
|
|
||
|
if (!mimeType.isEmpty())
|
||
|
{
|
||
|
medium->setMimeType( mimeType );
|
||
|
}
|
||
|
|
||
|
if (!iconName.isEmpty())
|
||
|
{
|
||
|
medium->setIconName( iconName );
|
||
|
}
|
||
|
|
||
|
if (!label.isEmpty())
|
||
|
{
|
||
|
medium->setLabel( label );
|
||
|
}
|
||
|
|
||
|
emit mediumStateChanged(id, medium->name(),
|
||
|
!medium->needMounting(),
|
||
|
allowNotification);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool MediaList::setUserLabel(const TQString &name, const TQString &label)
|
||
15 years ago
|
{
|
||
|
kdDebug(1219) << "MediaList::setUserLabel(" << name << ", "
|
||
|
<< label << ")" << endl;
|
||
|
|
||
13 years ago
|
if ( !m_nameMap.contains(name) ) return false;
|
||
15 years ago
|
|
||
|
Medium *medium = m_nameMap[name];
|
||
|
medium->setUserLabel(label);
|
||
|
|
||
|
emit mediumStateChanged(medium->id(), name,
|
||
|
!medium->needMounting(),
|
||
|
false);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
#include "medialist.moc"
|