summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-01-29 05:45:29 (UTC)
committer zautrix <zautrix>2005-01-29 05:45:29 (UTC)
commit0850ade22908615389800c6ee973f5906154d980 (patch) (side-by-side diff)
treef15401c42b2b4e86662f478c7e148c8de1a04b2b
parenta710cbadcbce154dff51445e756f8e3fc77278f9 (diff)
downloadkdepimpi-0850ade22908615389800c6ee973f5906154d980.zip
kdepimpi-0850ade22908615389800c6ee973f5906154d980.tar.gz
kdepimpi-0850ade22908615389800c6ee973f5906154d980.tar.bz2
desktop fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addresseedialog.cpp2
-rw-r--r--microkde/kdecore/kstandarddirs.cpp14
2 files changed, 14 insertions, 2 deletions
diff --git a/kabc/addresseedialog.cpp b/kabc/addresseedialog.cpp
index 9ea9d04..34f4160 100644
--- a/kabc/addresseedialog.cpp
+++ b/kabc/addresseedialog.cpp
@@ -1,293 +1,293 @@
/*
This file is part of libkabc.
Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <qlayout.h>
#include <qpushbutton.h>
#include <qgroupbox.h>
#include <qapplication.h>
#include <qregexp.h>
#include <klocale.h>
#include <kdebug.h>
#include <kglobalsettings.h>
#include "stdaddressbook.h"
#include "addresseedialog.h"
//#include "addresseedialog.moc"
using namespace KABC;
AddresseeItem::AddresseeItem( QListView *parent, const Addressee &addressee ) :
QListViewItem( parent ),
mAddressee( addressee )
{
QString name = addressee.familyName()+", "+ addressee.givenName();
if ( name.length() == 2 )
name = addressee.organization();
setText( Name,name);
setText( Email, addressee.preferredEmail() );
}
QString AddresseeItem::key( int column, bool ) const
{
if (column == Email) {
QString value = text(Email);
int val = value.findRev("@");
return value.mid( val) + value.left( val );
}
return text(column).lower();
}
AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) :
KDialogBase( KDialogBase::Plain, i18n("Select Addressee"),
Ok|Cancel, Ok, parent ), mMultiple( multiple )
{
QWidget *topWidget = plainPage();
QBoxLayout *topLayout = new QHBoxLayout( topWidget );
QBoxLayout *listLayout = new QVBoxLayout;
topLayout->addLayout( listLayout );
mAddresseeList = new KListView( topWidget );
mAddresseeList->addColumn( i18n("Name") );
mAddresseeList->addColumn( i18n("Email") );
mAddresseeList->setAllColumnsShowFocus( true );
mAddresseeList->setFullWidth( true );
listLayout->addWidget( mAddresseeList );
connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ),
SLOT( slotOk() ) );
mAddresseeEdit = new QLineEdit( topWidget );
connect( mAddresseeEdit, SIGNAL( returnPressed() ),
SLOT( loadAddressBook() ) );
mAddresseeEdit->setFocus();
listLayout->addWidget( mAddresseeEdit );
if ( mMultiple ) {
QBoxLayout *selectedLayout = new QVBoxLayout;
topLayout->addLayout( selectedLayout );
topLayout->setSpacing( spacingHint() );
QGroupBox *selectedGroup = new QGroupBox( 1, Horizontal, i18n("Selected"),
topWidget );
selectedLayout->addWidget( selectedGroup );
mSelectedList = new KListView( selectedGroup );
mSelectedList->addColumn( i18n("Name") );
mSelectedList->addColumn( i18n("Email") );
mSelectedList->setAllColumnsShowFocus( true );
mSelectedList->setFullWidth( true );
connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ),
SLOT( removeSelected() ) );
QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup );
connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) );
connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ),
SLOT( addSelected( QListViewItem * ) ) );
connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ),
SLOT( selectNextItem( QListViewItem * ) ) );
}
mAddressBook = StdAddressBook::self( true );
connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ),
SLOT( addressBookChanged() ) );
connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ),
SLOT( addressBookChanged() ) );
loadAddressBook();
}
AddresseeDialog::~AddresseeDialog()
{
}
void AddresseeDialog::loadAddressBook()
{
mAddresseeList->clear();
mItemDict.clear();
if ( mAddresseeEdit->text().isEmpty() ) {
AddressBook::Iterator it;
for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
continue;
new AddresseeItem( mAddresseeList, (*it) );
}
return;
}
//mAddresseeEdit->completionObject()->clear();
QRegExp re;
re.setWildcard(true); // most people understand these better.
re.setCaseSensitive(false);
re.setPattern( "*"+ mAddresseeEdit->text() + "*");
AddressBook::Iterator it;
for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
continue;
QString name = (*it).familyName()+", "+ (*it).givenName();
if ( name.length() == 2 )
name = (*it).realName();
name += (*it).preferredEmail();
-#if QT_VERSION >= 300
+#if QT_VERSION >= 0x030000
if (re.search(name) != -1)
#else
if (re.match(name) != -1)
#endif
AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) );
}
}
void AddresseeDialog::addCompletionItem( const QString &str, QListViewItem *item )
{
if ( str.isEmpty() ) return;
mItemDict.insert( str, item );
//mAddresseeEdit->completionObject()->addItem( str );
}
void AddresseeDialog::selectItem( const QString &str )
{
if ( str.isEmpty() ) return;
QListViewItem *item = mItemDict.find( str );
if ( item ) {
mAddresseeList->blockSignals( true );
mAddresseeList->setSelected( item, true );
mAddresseeList->ensureItemVisible( item );
mAddresseeList->blockSignals( false );
}
}
void AddresseeDialog::updateEdit( QListViewItem *item )
{
mAddresseeEdit->setText( item->text( 0 ) );
mAddresseeEdit->setSelection( 0, item->text( 0 ).length() );
}
void AddresseeDialog::selectNextItem( QListViewItem *item )
{
addSelected( item );
QListViewItem *next = item->nextSibling();
if ( next ) {
next->setSelected( true );
item->setSelected( false );
mAddresseeList->setCurrentItem( next );
}
}
void AddresseeDialog::addSelected( QListViewItem *item )
{
AddresseeItem *addrItem = (AddresseeItem *)( item );
if ( !addrItem ) return;
Addressee a = addrItem->addressee();
QListViewItem *selectedItem = mSelectedDict.find( a.uid() );
if ( !selectedItem ) {
selectedItem = new AddresseeItem( mSelectedList, a );
mSelectedDict.insert( a.uid(), selectedItem );
}
}
void AddresseeDialog::removeSelected()
{
QListViewItem *item = mSelectedList->selectedItem();
AddresseeItem *addrItem = (AddresseeItem *)( item );
if ( !addrItem ) return;
QListViewItem *next = item->nextSibling();
mSelectedDict.remove( addrItem->addressee().uid() );
delete addrItem;
if ( next )
next->setSelected( true );
}
Addressee AddresseeDialog::addressee()
{
AddresseeItem *aItem = 0;
if ( mMultiple )
aItem = (AddresseeItem *)( mSelectedList->firstChild() );
else
aItem = (AddresseeItem *)( mAddresseeList->selectedItem() );
if (aItem) return aItem->addressee();
return Addressee();
}
Addressee::List AddresseeDialog::addressees()
{
Addressee::List al;
AddresseeItem *aItem = 0;
if ( mMultiple ) {
QListViewItem *item = mSelectedList->firstChild();
while( item ) {
aItem = (AddresseeItem *)( item );
if ( aItem ) al.append( aItem->addressee() );
item = item->nextSibling();
}
}
else
{
aItem = (AddresseeItem *)( mAddresseeList->selectedItem() );
if (aItem) al.append( aItem->addressee() );
}
return al;
}
Addressee AddresseeDialog::getAddressee( QWidget *parent )
{
AddresseeDialog *dlg = new AddresseeDialog( parent );
Addressee addressee;
int result = dlg->exec();
if ( result == QDialog::Accepted ) {
addressee = dlg->addressee();
}
delete dlg;
return addressee;
}
Addressee::List AddresseeDialog::getAddressees( QWidget *parent )
{
AddresseeDialog *dlg = new AddresseeDialog( parent, true );
Addressee::List addressees;
if ( QApplication::desktop()->width() <= 640 )
dlg->showMaximized();
int result = dlg->exec();
if ( result == QDialog::Accepted ) {
addressees = dlg->addressees();
}
delete dlg;
return addressees;
}
void AddresseeDialog::addressBookChanged()
{
loadAddressBook();
}
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp
index f3584d7..cf0d1ee 100644
--- a/microkde/kdecore/kstandarddirs.cpp
+++ b/microkde/kdecore/kstandarddirs.cpp
@@ -1030,513 +1030,525 @@ QString KStandardDirs::saveLocation(const char *type,
}
else {
dirs = absolutes.find(type);
if (!dirs)
qFatal("KStandardDirs: The resource type %s is not registered", type);
pPath = new QString(realPath(dirs->last()));
}
savelocations.insert(type, pPath);
}
QString fullPath = *pPath + suffix;
//US struct stat st;
//US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode)))
QFileInfo fullPathInfo(QFile::encodeName(fullPath));
if (fullPathInfo.isReadable() || !fullPathInfo.isDir())
{
if(!create) {
#ifndef NDEBUG
qDebug("save location %s doesn't exist", fullPath.latin1());
#endif
return fullPath;
}
if(!makeDir(fullPath, 0700)) {
qWarning("failed to create %s", fullPath.latin1());
return fullPath;
}
dircache.remove(type);
}
return fullPath;
}
QString KStandardDirs::relativeLocation(const char *type, const QString &absPath)
{
QString fullPath = absPath;
int i = absPath.findRev('/');
if (i != -1)
{
fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize
}
QStringList candidates = resourceDirs(type);
for (QStringList::ConstIterator it = candidates.begin();
it != candidates.end(); it++)
if (fullPath.startsWith(*it))
{
return fullPath.mid((*it).length());
}
return absPath;
}
bool KStandardDirs::makeDir(const QString& dir2, int mode)
{
QString dir = QDir::convertSeparators( dir2 );
#if 0
//LR
// we want an absolute path
if (dir.at(0) != '/')
return false;
QString target = dir;
uint len = target.length();
// append trailing slash if missing
if (dir.at(len - 1) != '/')
target += '/';
QString base("");
uint i = 1;
while( i < len )
{
//US struct stat st;
int pos = target.find('/', i);
base += target.mid(i - 1, pos - i + 1);
QCString baseEncoded = QFile::encodeName(base);
// bail out if we encountered a problem
//US if (stat(baseEncoded, &st) != 0)
QFileInfo baseEncodedInfo(baseEncoded);
if (!baseEncodedInfo.exists())
{
// Directory does not exist....
// Or maybe a dangling symlink ?
//US if (lstat(baseEncoded, &st) == 0)
if (baseEncodedInfo.isSymLink()) {
//US (void)unlink(baseEncoded); // try removing
QFile(baseEncoded).remove();
}
//US if ( mkdir(baseEncoded, (mode_t) mode) != 0)
QDir dirObj;
if ( dirObj.mkdir(baseEncoded) != true )
{
//US perror("trying to create local folder");
return false; // Couldn't create it :-(
}
}
i = pos + 1;
}
return true;
#endif
// ********************************************
// new code for WIN32
QDir dirObj;
// we want an absolute path
#ifndef _WIN32_
if (dir.at(0) != '/')
return false;
#endif
QString target = dir;
uint len = target.length();
#ifndef _WIN32_
// append trailing slash if missing
if (dir.at(len - 1) != '/')
target += '/';
#endif
QString base("");
uint i = 1;
while( i < len )
{
//US struct stat st;
#ifndef _WIN32_
int pos = target.find('/', i);
#else
int pos = target.find('\\', i);
#endif
if ( pos < 0 )
return true;
base += target.mid(i - 1, pos - i + 1);
//QMessageBox::information( 0,"cap111", base, 1 );
/*US
QCString baseEncoded = QFile::encodeName(base);
// bail out if we encountered a problem
if (stat(baseEncoded, &st) != 0)
{
// Directory does not exist....
// Or maybe a dangling symlink ?
if (lstat(baseEncoded, &st) == 0)
(void)unlink(baseEncoded); // try removing
if ( mkdir(baseEncoded, (mode_t) mode) != 0) {
perror("trying to create local folder");
return false; // Couldn't create it :-(
}
}
*/
if (dirObj.exists(base) == false)
{
//qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1());
if (dirObj.mkdir(base) != true)
{
qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1());
return false;
}
}
i = pos + 1;
}
return true;
}
static QString readEnvPath(const char *env)
{
//#ifdef _WIN32_
// return "";
//#else
QCString c_path;
if ( getenv(env) != NULL )
c_path = QString ( getenv(env) );
if (c_path.isEmpty())
return QString::null;
return QFile::decodeName(c_path);
//#endif
}
void KStandardDirs::addKDEDefaults()
{
//qDebug("ERROR: KStandardDirs::addKDEDefaults() called ");
//return;
QStringList kdedirList;
// begin KDEDIRS
QString kdedirs = readEnvPath("MICROKDEDIRS");
if (!kdedirs.isEmpty())
{
tokenize(kdedirList, kdedirs, ":");
}
else
{
QString kdedir = readEnvPath("MICROKDEDIR");
if (!kdedir.isEmpty())
{
kdedir = KShell::tildeExpand(kdedir);
kdedirList.append(kdedir);
}
}
//US kdedirList.append(KDEDIR);
//US for embedded, add qtopia dir as kdedir
#ifndef DESKTOP_VERSION
QString tmp = readEnvPath("QPEDIR");
if (!tmp.isEmpty())
kdedirList.append(tmp);
tmp = readEnvPath("QTDIR");
if (!tmp.isEmpty())
kdedirList.append(tmp);
tmp = readEnvPath("OPIEDIR");
if (!tmp.isEmpty())
kdedirList.append(tmp);
#endif
#ifdef __KDE_EXECPREFIX
QString execPrefix(__KDE_EXECPREFIX);
if (execPrefix!="NONE")
kdedirList.append(execPrefix);
#endif
QString localKdeDir;
//US if (getuid())
if (true)
{
localKdeDir = readEnvPath("MICROKDEHOME");
if (!localKdeDir.isEmpty())
{
#ifdef _WIN32_
if (localKdeDir.at(localKdeDir.length()-1) != '\\')
localKdeDir += '\\';
#else
if (localKdeDir.at(localKdeDir.length()-1) != '/')
localKdeDir += '/';
#endif
//QMessageBox::information( 0,"localKdeDir",localKdeDir, 1 );
}
else
{
- KConfig cfg ( QDir::homeDirPath() + "/.microkdehome" );
+ QString confFile;
+#ifdef DESKTOP_VERSION
+ confFile = qApp->applicationDirPath ()+ "/.microkdehome" ;
+ QFileInfo fi ( confFile );
+ if ( !fi.exists() )
+ confFile = QDir::homeDirPath() + "/.microkdehome";
+ else
+ qDebug("Loading path info from " + confFile );
+
+#else
+ confFile = QDir::homeDirPath() + "/.microkdehome";
+#endif
+ KConfig cfg ( confFile );
cfg.setGroup("Global");
localKdeDir = cfg.readEntry( "MICROKDEHOME", QDir::homeDirPath() + "/kdepim/" );
}
}
else
{
// We treat root different to prevent root messing up the
// file permissions in the users home directory.
localKdeDir = readEnvPath("MICROKDEROOTHOME");
if (!localKdeDir.isEmpty())
{
if (localKdeDir.at(localKdeDir.length()-1) != '/')
localKdeDir += '/';
}
else
{
//US struct passwd *pw = getpwuid(0);
//US localKdeDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.microkde/";
qDebug("KStandardDirs::addKDEDefaults: 1 has to be fixed");
}
}
//US localKdeDir = appDir();
//US
// qDebug("KStandardDirs::addKDEDefaults: localKdeDir=%s", localKdeDir.latin1());
if (localKdeDir != "-/")
{
localKdeDir = KShell::tildeExpand(localKdeDir);
addPrefix(localKdeDir);
}
for (QStringList::ConstIterator it = kdedirList.begin();
it != kdedirList.end(); it++)
{
QString dir = KShell::tildeExpand(*it);
addPrefix(dir);
}
// end KDEDIRS
// begin XDG_CONFIG_XXX
QStringList xdgdirList;
QString xdgdirs = readEnvPath("XDG_CONFIG_DIRS");
if (!xdgdirs.isEmpty())
{
tokenize(xdgdirList, xdgdirs, ":");
}
else
{
xdgdirList.clear();
xdgdirList.append("/etc/xdg");
}
QString localXdgDir = readEnvPath("XDG_CONFIG_HOME");
if (!localXdgDir.isEmpty())
{
if (localXdgDir.at(localXdgDir.length()-1) != '/')
localXdgDir += '/';
}
else
{
//US if (getuid())
if (true)
{
localXdgDir = QDir::homeDirPath() + "/.config/";
}
else
{
//US struct passwd *pw = getpwuid(0);
//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.config/";
qDebug("KStandardDirs::addKDEDefaults: 2 has to be fixed");
}
}
localXdgDir = KShell::tildeExpand(localXdgDir);
addXdgConfigPrefix(localXdgDir);
for (QStringList::ConstIterator it = xdgdirList.begin();
it != xdgdirList.end(); it++)
{
QString dir = KShell::tildeExpand(*it);
addXdgConfigPrefix(dir);
}
// end XDG_CONFIG_XXX
// begin XDG_DATA_XXX
xdgdirs = readEnvPath("XDG_DATA_DIRS");
if (!xdgdirs.isEmpty())
{
tokenize(xdgdirList, xdgdirs, ":");
}
else
{
xdgdirList.clear();
for (QStringList::ConstIterator it = kdedirList.begin();
it != kdedirList.end(); it++)
{
QString dir = *it;
if (dir.at(dir.length()-1) != '/')
dir += '/';
xdgdirList.append(dir+"share/");
}
xdgdirList.append("/usr/local/share/");
xdgdirList.append("/usr/share/");
}
localXdgDir = readEnvPath("XDG_DATA_HOME");
if (!localXdgDir.isEmpty())
{
if (localXdgDir.at(localXdgDir.length()-1) != '/')
localXdgDir += '/';
}
else
{
//US if (getuid())
if (true)
{
localXdgDir = QDir::homeDirPath() + "/.local/share/";
}
else
{
//US struct passwd *pw = getpwuid(0);
//US localXdgDir = QFile::decodeName((pw && pw->pw_dir) ? pw->pw_dir : "/root") + "/.local/share/";
qDebug("KStandardDirs::addKDEDefaults: 3 has to be fixed");
}
}
localXdgDir = KShell::tildeExpand(localXdgDir);
addXdgDataPrefix(localXdgDir);
for (QStringList::ConstIterator it = xdgdirList.begin();
it != xdgdirList.end(); it++)
{
QString dir = KShell::tildeExpand(*it);
addXdgDataPrefix(dir);
}
// end XDG_DATA_XXX
uint index = 0;
while (types[index] != 0) {
addResourceType(types[index], kde_default(types[index]));
index++;
}
addResourceDir("home", QDir::homeDirPath());
}
void KStandardDirs::checkConfig() const
{
/*US
if (!addedCustoms && KGlobal::_instance && KGlobal::_instance->_config)
const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::_instance->_config);
*/
if (!addedCustoms && KGlobal::config())
const_cast<KStandardDirs*>(this)->addCustomized(KGlobal::config());
}
bool KStandardDirs::addCustomized(KConfig *config)
{
if (addedCustoms) // there are already customized entries
return false; // we just quite and hope they are the right ones
// save the numbers of config directories. If this changes,
// we will return true to give KConfig a chance to reparse
uint configdirs = resourceDirs("config").count();
// reading the prefixes in
QString oldGroup = config->group();
config->setGroup("Directories");
QStringList list;
QStringList::ConstIterator it;
list = config->readListEntry("prefixes");
for (it = list.begin(); it != list.end(); it++)
addPrefix(*it);
// iterating over all entries in the group Directories
// to find entries that start with dir_$type
/*US
QMap<QString, QString> entries = config->entryMap("Directories");
QMap<QString, QString>::ConstIterator it2;
for (it2 = entries.begin(); it2 != entries.end(); it2++)
{
QString key = it2.key();
if (key.left(4) == "dir_") {
// generate directory list, there may be more than 1.
QStringList dirs = QStringList::split(',', *it2);
QStringList::Iterator sIt(dirs.begin());
QString resType = key.mid(4, key.length());
for (; sIt != dirs.end(); ++sIt) {
addResourceDir(resType.latin1(), *sIt);
}
}
}
// Process KIOSK restrictions.
config->setGroup("KDE Resource Restrictions");
entries = config->entryMap("KDE Resource Restrictions");
for (it2 = entries.begin(); it2 != entries.end(); it2++)
{
QString key = it2.key();
if (!config->readBoolEntry(key, true))
{
d->restrictionsActive = true;
d->restrictions.insert(key.latin1(), &d->restrictionsActive); // Anything will do
dircache.remove(key.latin1());
}
}
*/
// save it for future calls - that will return
addedCustoms = true;
config->setGroup(oldGroup);
// return true if the number of config dirs changed
return (resourceDirs("config").count() != configdirs);
}
QString KStandardDirs::localkdedir() const
{
// Return the prefix to use for saving
return prefixes.first();
}
QString KStandardDirs::localxdgdatadir() const
{
// Return the prefix to use for saving
return d->xdgdata_prefixes.first();
}
QString KStandardDirs::localxdgconfdir() const
{
// Return the prefix to use for saving
return d->xdgconf_prefixes.first();
}
void KStandardDirs::setAppDir( const QString &appDir )
{
mAppDir = appDir;
if ( mAppDir.right( 1 ) != "/" )
mAppDir += "/";
}
QString KStandardDirs::appDir()
{
return mAppDir;
}
// just to make code more readable without macros
QString locate( const char *type,
const QString& filename/*US , const KInstance* inst*/ )