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.
229 lines
5.1 KiB
229 lines
5.1 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (c) 2005 Kevin 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 as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
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 "homeimpl.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
14 years ago
|
#include <tqapplication.h>
|
||
|
#include <tqeventloop.h>
|
||
15 years ago
|
|
||
|
#include <sys/stat.h>
|
||
|
|
||
|
#define MINIMUM_UID 500
|
||
|
|
||
|
HomeImpl::HomeImpl()
|
||
|
{
|
||
|
KUser user;
|
||
|
m_effectiveUid = user.uid();
|
||
|
}
|
||
|
|
||
14 years ago
|
bool HomeImpl::parseURL(const KURL &url, TQString &name, TQString &path) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString url_path = url.path();
|
||
15 years ago
|
|
||
13 years ago
|
int i = url_path.find('/', 1);
|
||
15 years ago
|
if (i > 0)
|
||
|
{
|
||
|
name = url_path.mid(1, i-1);
|
||
|
path = url_path.mid(i+1);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
name = url_path.mid(1);
|
||
14 years ago
|
path = TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
return name != TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
bool HomeImpl::realURL(const TQString &name, const TQString &path, KURL &url)
|
||
15 years ago
|
{
|
||
|
KUser user(name);
|
||
|
|
||
|
if ( user.isValid() )
|
||
|
{
|
||
|
KURL res;
|
||
|
res.setPath( user.homeDir() );
|
||
|
res.addPath(path);
|
||
|
url = res;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
bool HomeImpl::listHomes(TQValueList<TDEIO::UDSEntry> &list)
|
||
15 years ago
|
{
|
||
|
kdDebug() << "HomeImpl::listHomes" << endl;
|
||
|
|
||
|
KUser current_user;
|
||
14 years ago
|
TQValueList<KUserGroup> groups = current_user.groups();
|
||
|
TQValueList<int> uid_list;
|
||
15 years ago
|
|
||
14 years ago
|
TQValueList<KUserGroup>::iterator groups_it = groups.begin();
|
||
|
TQValueList<KUserGroup>::iterator groups_end = groups.end();
|
||
15 years ago
|
|
||
|
for(; groups_it!=groups_end; ++groups_it)
|
||
|
{
|
||
14 years ago
|
TQValueList<KUser> users = (*groups_it).users();
|
||
15 years ago
|
|
||
14 years ago
|
TQValueList<KUser>::iterator it = users.begin();
|
||
|
TQValueList<KUser>::iterator users_end = users.end();
|
||
15 years ago
|
|
||
|
for(; it!=users_end; ++it)
|
||
|
{
|
||
|
if ((*it).uid()>=MINIMUM_UID
|
||
13 years ago
|
&& !uid_list.contains( (*it).uid() ) )
|
||
15 years ago
|
{
|
||
|
uid_list.append( (*it).uid() );
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
createHomeEntry(entry, *it);
|
||
|
list.append(entry);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
static void addAtom(TDEIO::UDSEntry &entry, unsigned int ID, long l,
|
||
14 years ago
|
const TQString &s = TQString::null)
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEIO::UDSAtom atom;
|
||
15 years ago
|
atom.m_uds = ID;
|
||
|
atom.m_long = l;
|
||
|
atom.m_str = s;
|
||
|
entry.append(atom);
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void HomeImpl::createTopLevelEntry(TDEIO::UDSEntry &entry) const
|
||
15 years ago
|
{
|
||
|
entry.clear();
|
||
12 years ago
|
addAtom(entry, TDEIO::UDS_NAME, 0, ".");
|
||
|
addAtom(entry, TDEIO::UDS_FILE_TYPE, S_IFDIR);
|
||
|
addAtom(entry, TDEIO::UDS_ACCESS, 0555);
|
||
|
addAtom(entry, TDEIO::UDS_MIME_TYPE, 0, "inode/directory");
|
||
|
addAtom(entry, TDEIO::UDS_ICON_NAME, 0, "kfm_home");
|
||
|
addAtom(entry, TDEIO::UDS_USER, 0, "root");
|
||
|
addAtom(entry, TDEIO::UDS_GROUP, 0, "root");
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void HomeImpl::createHomeEntry(TDEIO::UDSEntry &entry,
|
||
15 years ago
|
const KUser &user)
|
||
|
{
|
||
|
kdDebug() << "HomeImpl::createHomeEntry" << endl;
|
||
|
|
||
|
entry.clear();
|
||
|
|
||
14 years ago
|
TQString full_name = user.loginName();
|
||
15 years ago
|
|
||
|
if (!user.fullName().isEmpty())
|
||
|
{
|
||
|
full_name = user.fullName()+" ("+user.loginName()+")";
|
||
|
}
|
||
|
|
||
12 years ago
|
full_name = TDEIO::encodeFileName( full_name );
|
||
15 years ago
|
|
||
12 years ago
|
addAtom(entry, TDEIO::UDS_NAME, 0, full_name);
|
||
|
addAtom(entry, TDEIO::UDS_URL, 0, "home:/"+user.loginName());
|
||
15 years ago
|
|
||
12 years ago
|
addAtom(entry, TDEIO::UDS_FILE_TYPE, S_IFDIR);
|
||
|
addAtom(entry, TDEIO::UDS_MIME_TYPE, 0, "inode/directory");
|
||
15 years ago
|
|
||
14 years ago
|
TQString icon_name = "folder_home2";
|
||
15 years ago
|
|
||
|
if (user.uid()==m_effectiveUid)
|
||
|
{
|
||
|
icon_name = "folder_home";
|
||
|
}
|
||
|
|
||
12 years ago
|
addAtom(entry, TDEIO::UDS_ICON_NAME, 0, icon_name);
|
||
15 years ago
|
|
||
|
KURL url;
|
||
|
url.setPath(user.homeDir());
|
||
|
entry += extractUrlInfos(url);
|
||
|
}
|
||
|
|
||
12 years ago
|
bool HomeImpl::statHome(const TQString &name, TDEIO::UDSEntry &entry)
|
||
15 years ago
|
{
|
||
|
kdDebug() << "HomeImpl::statHome: " << name << endl;
|
||
|
|
||
|
KUser user(name);
|
||
|
|
||
|
if (user.isValid())
|
||
|
{
|
||
|
createHomeEntry(entry, user);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
12 years ago
|
void HomeImpl::slotStatResult(TDEIO::Job *job)
|
||
15 years ago
|
{
|
||
|
if ( job->error() == 0)
|
||
|
{
|
||
12 years ago
|
TDEIO::StatJob *stat_job = static_cast<TDEIO::StatJob *>(job);
|
||
15 years ago
|
m_entryBuffer = stat_job->statResult();
|
||
|
}
|
||
|
|
||
14 years ago
|
tqApp->eventLoop()->exitLoop();
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEIO::UDSEntry HomeImpl::extractUrlInfos(const KURL &url)
|
||
15 years ago
|
{
|
||
|
m_entryBuffer.clear();
|
||
|
|
||
12 years ago
|
TDEIO::StatJob *job = TDEIO::stat(url, false);
|
||
|
connect( job, TQT_SIGNAL( result(TDEIO::Job *) ),
|
||
|
this, TQT_SLOT( slotStatResult(TDEIO::Job *) ) );
|
||
14 years ago
|
tqApp->eventLoop()->enterLoop();
|
||
15 years ago
|
|
||
12 years ago
|
TDEIO::UDSEntry::iterator it = m_entryBuffer.begin();
|
||
|
TDEIO::UDSEntry::iterator end = m_entryBuffer.end();
|
||
15 years ago
|
|
||
12 years ago
|
TDEIO::UDSEntry infos;
|
||
15 years ago
|
|
||
|
for(; it!=end; ++it)
|
||
|
{
|
||
|
switch( (*it).m_uds )
|
||
|
{
|
||
12 years ago
|
case TDEIO::UDS_ACCESS:
|
||
|
case TDEIO::UDS_USER:
|
||
|
case TDEIO::UDS_GROUP:
|
||
|
case TDEIO::UDS_CREATION_TIME:
|
||
|
case TDEIO::UDS_MODIFICATION_TIME:
|
||
|
case TDEIO::UDS_ACCESS_TIME:
|
||
15 years ago
|
infos.append(*it);
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
addAtom(infos, TDEIO::UDS_LOCAL_PATH, 0, url.path());
|
||
15 years ago
|
|
||
|
return infos;
|
||
|
}
|
||
|
|
||
|
#include "homeimpl.moc"
|
||
|
|