Commit 48ef299e authored by Tom Albers's avatar Tom Albers
Browse files

Add dbus interface to retrieve a localised version of the name and description of resources.

svn path=/trunk/kdesupport/akonadi/; revision=998932
parent efad024a
......@@ -47,9 +47,19 @@
<arg type="s" direction="out"/>
<arg name="identifier" type="s" direction="in"/>
</method>
<method name="agentName">
<arg type="s" direction="out"/>
<arg name="identifier" type="s" direction="in"/>
<arg name="language" type="s" direction="in"/>
</method>
<method name="agentComment">
<arg type="s" direction="out"/>
<arg name="identifier" type="s" direction="in"/>
</method>
<method name="agentComment">
<arg type="s" direction="out"/>
<arg name="identifier" type="s" direction="in"/>
<arg name="language" type="s" direction="in"/>
</method>
<method name="agentIcon">
<arg type="s" direction="out"/>
......@@ -101,6 +111,11 @@
<arg type="s" direction="out"/>
<arg name="identifier" type="s" direction="in"/>
</method>
<method name="agentInstanceName">
<arg type="s" direction="out"/>
<arg name="identifier" type="s" direction="in"/>
<arg name="language" type="s" direction="in"/>
</method>
<method name="agentInstanceConfigure">
<arg name="identifier" type="s" direction="in"/>
<arg name="windowId" type="x" direction="in"/>
......
......@@ -114,18 +114,20 @@ QStringList AgentManager::agentTypes() const
return mAgents.keys();
}
QString AgentManager::agentName( const QString &identifier ) const
QString AgentManager::agentName( const QString &identifier, const QString& lang ) const
{
if ( !checkAgentExists( identifier ) )
return QString();
return mAgents.value( identifier ).name;
const QString name = mAgents.value( identifier ).name.value( lang );
return name.isEmpty() ? mAgents.value( identifier ).name.value( "en_US" ) : name;
}
QString AgentManager::agentComment( const QString &identifier ) const
QString AgentManager::agentComment( const QString &identifier, const QString& lang ) const
{
if ( !checkAgentExists( identifier ) )
return QString();
return mAgents.value( identifier ).comment;
const QString comment = mAgents.value( identifier ).comment.value( lang );
return comment.isEmpty() ? mAgents.value( identifier ).comment.value( "en_US" ) : comment;
}
QString AgentManager::agentIcon( const QString &identifier ) const
......@@ -282,7 +284,7 @@ void AgentManager::setAgentInstanceName( const QString &identifier, const QStrin
mAgentInstances.value( identifier )->resourceInterface()->setName( name );
}
QString AgentManager::agentInstanceName( const QString &identifier ) const
QString AgentManager::agentInstanceName( const QString &identifier, const QString &lang ) const
{
if ( !checkInstance( identifier ) )
return QString();
......@@ -291,7 +293,8 @@ QString AgentManager::agentInstanceName( const QString &identifier ) const
return inst->resourceName();
if ( !checkAgentExists( inst->agentType() ) )
return QString();
return mAgents.value( inst->agentType() ).name;
const QString name = mAgents.value( inst->agentType() ).name.value( lang );
return name.isEmpty() ? mAgents.value( inst->agentType() ).name.value("en_US") : name;
}
void AgentManager::agentInstanceSynchronize( const QString &identifier )
......
......@@ -81,15 +81,15 @@ class AgentManager : public QObject
/**
* Returns the i18n'ed name of the agent type for
* the given @p identifier.
* the given @p identifier and the given @p language.
*/
QString agentName( const QString &identifier ) const;
QString agentName( const QString &identifier, const QString &language = QString("en_US") ) const;
/**
* Returns the i18n'ed comment of the agent type for
* the given @p identifier.
* the given @p identifier and the given @p language.
*/
QString agentComment( const QString &identifier ) const;
QString agentComment( const QString &identifier, const QString &language = QString("en_US") ) const;
/**
* Returns the icon name of the agent type for the
......@@ -166,8 +166,10 @@ class AgentManager : public QObject
/**
* Returns the name of the agent instance with the given @p identifier.
* If there is no name, it returns the default name of the agent, you can tweak
* the language for that name with the @p language setting.
*/
QString agentInstanceName( const QString &identifier ) const;
QString agentInstanceName( const QString &identifier, const QString &language = QString( "en_US" ) ) const;
/**
* Triggers the agent instance with the given @p identifier to show
......
......@@ -40,8 +40,19 @@ bool AgentType::load(const QString & fileName, AgentManager * manager)
QSettings file( fileName, QSettings::IniFormat );
file.beginGroup( "Desktop Entry" );
name = file.value( "Name" ).toString();
comment = file.value( "Comment" ).toString();
foreach(const QString& key, file.allKeys() ) {
if ( key.startsWith( "Name[" ) ) {
QString lang = key.mid( 5, key.length()-6);
name.insert( lang, QString::fromUtf8( file.value( key ).toByteArray() ) );
} else if ( key == "Name" ) {
name.insert( "en_US", QString::fromUtf8( file.value( "Name" ).toByteArray() ) );
} else if ( key.startsWith( "Comment[" ) ) {
QString lang = key.mid( 8, key.length()-9);
comment.insert( lang, QString::fromUtf8( file.value( key ).toByteArray() ) );
} else if ( key == "Comment" ) {
comment.insert( "en_US", QString::fromUtf8( file.value( "Comment" ).toByteArray() ) );
}
}
icon = file.value( "Icon" ).toString();
mimeTypes = file.value( "X-Akonadi-MimeTypes" ).toStringList();
capabilities = file.value( "X-Akonadi-Capabilities" ).toStringList();
......
......@@ -22,6 +22,7 @@
#include <QString>
#include <QStringList>
#include <QHash>
namespace Akonadi {
class ProcessControl;
......@@ -38,8 +39,8 @@ class AgentType
void save( QSettings *config ) const;
QString identifier;
QString name;
QString comment;
QHash<QString, QString> name;
QHash<QString, QString> comment;
QString icon;
QStringList mimeTypes;
QStringList capabilities;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment