Skip to content

Commit

Permalink
Merge branch 'scheme-handler' into 'master'
Browse files Browse the repository at this point in the history
Switch maemo handler type to linux desktop x-scheme-handler + random fixes

See merge request mer-core/libcontentaction!3
  • Loading branch information
pvuorela committed May 8, 2018
2 parents a80dd2d + efca62d commit 3280735
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 199 deletions.
5 changes: 5 additions & 0 deletions src/config.cpp
Expand Up @@ -90,6 +90,8 @@ bool ConfigReader::startElement(const QString& ns, const QString& name,
const QString& qname,
const QXmlAttributes &atts)
{
Q_UNUSED(ns)

switch (state) {
case inLimbo:
if (qname != "actions")
Expand Down Expand Up @@ -139,6 +141,9 @@ bool ConfigReader::characters(const QString& chars)
bool ConfigReader::endElement(const QString& nsuri, const QString& name,
const QString& qname)
{
Q_UNUSED(nsuri)
Q_UNUSED(name)

switch (state) {
case inActions:
if (qname == "actions")
Expand Down
5 changes: 0 additions & 5 deletions src/contentaction.h
Expand Up @@ -36,7 +36,6 @@
# endif
#endif

class MLabel;
class MDesktopEntry;

namespace ContentAction
Expand Down Expand Up @@ -109,9 +108,5 @@ LCA_EXPORT void setMimeDefault(const QString& mimeType, const Action& action);
LCA_EXPORT void setMimeDefault(const QString& mimeType, const QString& app);
LCA_EXPORT void resetMimeDefault(const QString& mimeType);

LCA_EXPORT void highlightLabel(MLabel *label);
LCA_EXPORT void highlightLabel(MLabel *label, QStringList typesToHighlight);
LCA_EXPORT void dehighlightLabel(MLabel *label);

} // end namespace
#endif
131 changes: 62 additions & 69 deletions src/contentinfo.cpp
Expand Up @@ -32,35 +32,35 @@
*/

struct ContentInfo::Private {
bool isValid;
QString mimeType;
QString icon;
QString description;
bool isValid;
QString mimeType;
QString icon;
QString description;
};

ContentInfo::ContentInfo ()
: priv(new Private)
ContentInfo::ContentInfo()
: priv(new Private)
{
priv->isValid = false;
priv->isValid = false;
}

ContentInfo::ContentInfo(Private *priv)
: priv(priv)
: priv(priv)
{
}

ContentInfo::ContentInfo(const ContentInfo& other)
: priv(other.priv)
: priv(other.priv)
{
}

ContentInfo& ContentInfo::operator=(const ContentInfo& other)
{
priv = other.priv;
return *this;
priv = other.priv;
return *this;
}

ContentInfo::~ContentInfo ()
ContentInfo::~ContentInfo()
{
}

Expand All @@ -71,108 +71,101 @@ ContentInfo::~ContentInfo ()
/// Invalid ContentInfo instances can still be accessed, but they will
/// return empty strings for mimeType, typeDescription, and typeIcon.
bool
ContentInfo::isValid () const
ContentInfo::isValid() const
{
return priv->isValid;
return priv->isValid;
}

/// Returns the mime type of this content object
QString
ContentInfo::mimeType () const
ContentInfo::mimeType() const
{
return priv->mimeType;
return priv->mimeType;
}

/// Returns a one-line, localized description of the type of the
/// content object.
QString
ContentInfo::typeDescription () const
ContentInfo::typeDescription() const
{
return priv->description;
return priv->description;
}

/// Returns the name of an icon to represent the type of this content
/// object.
QString
ContentInfo::typeIcon () const
ContentInfo::typeIcon() const
{
return priv->icon;
return priv->icon;
}

/// Returns information for the given mime type \a mimeType.
ContentInfo
ContentInfo::forMime (const QString &mimeType)
ContentInfo::forMime(const QString &mimeType)
{
g_type_init ();

gchar *contentType = g_content_type_from_mime_type (mimeType.toUtf8());

Private *priv = new Private;
priv->isValid = true;
priv->mimeType = mimeType;
if (contentType)
{
GIcon *icon = g_content_type_get_icon (contentType);
if (G_IS_THEMED_ICON(icon))
{
const gchar *const *names = g_themed_icon_get_names (G_THEMED_ICON(icon));
priv->icon = names[0];
gchar *contentType = g_content_type_from_mime_type(mimeType.toUtf8());

Private *priv = new Private;
priv->isValid = true;
priv->mimeType = mimeType;
if (contentType) {
GIcon *icon = g_content_type_get_icon(contentType);
if (G_IS_THEMED_ICON(icon)) {
const gchar *const *names = g_themed_icon_get_names(G_THEMED_ICON(icon));
priv->icon = names[0];
}
g_object_unref (icon);
g_object_unref(icon);

gchar* description = g_content_type_get_description (contentType);
// This will copy the data
priv->description = QString(description);
g_free (description);
gchar* description = g_content_type_get_description(contentType);
// This will copy the data
priv->description = QString(description);
g_free(description);

g_free (contentType);
g_free(contentType);
}
return ContentInfo(priv);
return ContentInfo(priv);
}

/// Returns information for the file identified by \a url. The file
/// does not need to exist. If it does, its content will be used to
/// guess its type; otherwise only the filename will be used.
ContentInfo
ContentInfo::forFile (const QUrl &url)
ContentInfo::forFile(const QUrl &url)
{
QString mime = ContentAction::Internal::mimeForFile (url);
if (!mime.isEmpty())
return forMime (mime);
else
return ContentInfo();
QString mime = ContentAction::Internal::mimeForFile(url);
if (!mime.isEmpty())
return forMime(mime);
else
return ContentInfo();
}

/// Returns information for the Tracker object identified by \a
/// tracker_uri.
ContentInfo
ContentInfo::forTracker (const QString &tracker_uri)
ContentInfo::forTracker(const QString &tracker_uri)
{
QStringList urlAndMime;
if (ContentAction::Internal::mimeAndUriFromTracker(QStringList() << tracker_uri, urlAndMime))
return forMime (urlAndMime[1]);
else
return ContentInfo();
QStringList urlAndMime;
if (ContentAction::Internal::mimeAndUriFromTracker(QStringList() << tracker_uri, urlAndMime))
return forMime(urlAndMime[1]);
else
return ContentInfo();
}

/// Returns information for the given \a bytes. The \a bytes are
/// assumed to be the first few bytes of a content object, and its
/// type is guessed from them.
ContentInfo
ContentInfo::forData (const QByteArray &bytes)
ContentInfo::forData(const QByteArray &bytes)
{
g_type_init ();

gchar *content_type = g_content_type_guess (NULL, (const guchar *)bytes.constData(), bytes.size(), NULL);
if (content_type)
{
gchar* mime_type = g_content_type_get_mime_type (content_type);
ContentInfo info = forMime (mime_type);
if (mime_type != 0)
g_free (mime_type);
g_free (content_type);
return info;
}
else
return ContentInfo();
gchar *content_type = g_content_type_guess(NULL, (const guchar *)bytes.constData(), bytes.size(), NULL);
if (content_type) {
gchar* mime_type = g_content_type_get_mime_type(content_type);
ContentInfo info = forMime(mime_type);
if (mime_type != 0)
g_free(mime_type);
g_free(content_type);
return info;
} else {
return ContentInfo();
}
}
8 changes: 4 additions & 4 deletions src/contentinfo.h
Expand Up @@ -49,10 +49,10 @@ class LCA_EXPORT ContentInfo
ContentInfo(const ContentInfo& other);
ContentInfo& operator=(const ContentInfo& other);

static ContentInfo forMime (const QString &mimeType);
static ContentInfo forTracker (const QString &trackerUri);
static ContentInfo forFile (const QUrl &file);
static ContentInfo forData (const QByteArray &arr);
static ContentInfo forMime(const QString &mimeType);
static ContentInfo forTracker(const QString &trackerUri);
static ContentInfo forFile(const QUrl &file);
static ContentInfo forData(const QByteArray &arr);

private:
struct Private;
Expand Down
43 changes: 8 additions & 35 deletions src/doc.h
Expand Up @@ -17,17 +17,14 @@ from libcontentaction.
For file URIs, the library finds out the MIME type and uses it as a key of the
association. For objects stored in Tracker, the library adds the custom MIME
types that target them. Finally, the library provides
ContentAction::highlightLabel(), which adds highlighters to an MLabel based on
the actions associated with regular expressions (such as phone numbers and
e-mail addresses).
types that target them.
Actions can target one of the following:
-# MIME types (\c image/jpeg)
-# Tracker-query based conditions (\c x-maemo-nepomuk/contact)
-# regular expressions (\c x-maemo-highlight/phonenumber)
-# URI schemes (\c x-maemo-urischeme/mailto)
-# URI schemes (\c x-scheme-handler/mailto)
\section detaileddescription Detailed description
Expand Down Expand Up @@ -115,15 +112,15 @@ More information:
In addition to the Exec line, .desktop files can specify custom ways to launch
the application. The launch methods supported by libcontentaction are:
-# launching a MeeGoTouch based application using the MApplication D-Bus interface
-# launching application using D-Bus interface
- Define: \c X-Maemo-Service=my.bus.name
- Optionally: \c X-Maemo-Fixed-Args=my;fixed;args
-# calling a D-Bus method specified in the .desktop file
- Define: \c X-Maemo-Service=my.bus.name
- Define: \c X-Maemo-Method=com.my.interface.Method
- Optionally: \c X-Maemo-Object-Path=/the/object/path (default: /)
- Optionally: \c X-Maemo-Fixed-Args=my;fixed;args
-# calling a MeeGo Service Framework method
-# calling a D-Bus method
- Define: \c X-Maemo-Method=com.my.interface.Method
- Optionally: \c X-Maemo-Fixed-Args=my;fixed;args
- Note: Do not define \c X-Maemo-Service
Expand All @@ -140,12 +137,6 @@ function is called, the strings are the URIs (or the free-text snippet)
used to construct the Action, as well as the fixed parameters you may have
specified. If there is a return value, it is ignored.
If you use a MeeGo Service Framework based invocation,
declare your application to be an implementor of the interface. You just need to
add an "Interface: " line to your D-Bus .service file. You can also publish
your interface in the meego-services package, but it is not needed for
libcontentaction.
If your application is running, D-Bus based launching delivers the
function call to the running instance. If your application is not running,
D-Bus can autolaunch it as defined in your .service file. This makes
Expand All @@ -160,8 +151,6 @@ More information:
<a href="http://dbus.freedesktop.org/doc/dbus-specification.html">Message Bus Starting Services</a>
<a href="http://apidocs.meego.com/mtf/index.html">MeeGoTouch</a>
\section custommime Custom MIME types for Tracker URIs
\attention
Expand Down Expand Up @@ -253,26 +242,14 @@ More information:
The libcontentaction library is also able to dispatch URIs based on the scheme
(ContentAction::Action::actionsForScheme). To this end, applications can
define that they handle a custom MIME type, for example,
\c x-maemo-urischeme/http. When actionsForScheme("http://www.example.com") is
called, applications declaring \c x-maemo-urischeme/http appear in the list of
\c x-scheme-handler/http. When actionsForScheme("http://www.example.com") is
called, applications declaring \c x-scheme-handler/http appear in the list of
applicable actions. When launched, an action gets the string
"http://www.example.com" as a parameter.
\section highlighter Free-text highlighter
\attention
The following section may be subject to changes!
Passing an MLabel* to ContentAction::Action::highlightLabel() adds a
MLabelHighlighter which highlights interesting elements inside the label. When
the user clicks a highlighted element, the default action for it is launched.
When the user long-clicks a highlighted element, a pop-up menu containing the
applicable actions is shown. When the user clicks an item in the menu, the
corresponding action is launched.
These actions have different semantics than ordinary Actions. When
triggered, they call the method with a single element list containing the
matched text (as UTF-8). Note that these are very likely invalid URIs.
FIXME: missing proper documentation for highlighting.
Similarly to Tracker conditions, regexps are also defined in .xml files
located in \c /usr/share/contentaction (unless overridden with
Expand All @@ -293,10 +270,6 @@ custom MIME types. When launched, they get a string which matches the regular
expression as a parameter. For example, an application handling
\c x-maemo-highlight/phone-number might get "+ 123 456-789" as a parameter.
More information:
<a href="http://apidocs.meego.com/mtf/class_m_label.html">MLabel documentation</a>
\section exampledesktop An example .desktop file
The following example illustrates the interesting .desktop file fields from the
Expand Down Expand Up @@ -325,7 +298,7 @@ MimeType=x-maemo-nepomuk/contact;
;; 3. pre-defined regexps for the highlighter
MimeType=x-maemo-highlight/phonenumber;
;; 4. URI schemes
MimeType=x-maemo-urischeme/mailto;
MimeType=x-scheme-handler/mailto;
;; Defining how to trigger the action:
;; 1. invoke a MApplication based program by calling
Expand Down
1 change: 0 additions & 1 deletion src/exec.cpp
Expand Up @@ -35,7 +35,6 @@ ExecPrivate::ExecPrivate(QSharedPointer<MDesktopEntry> desktopEntry,
const QStringList& params)
: DefaultPrivate(desktopEntry, params), appInfo(0)
{
g_type_init();
GError *execError = 0;
GKeyFile *keyFile;
GKeyFileFlags flags = G_KEY_FILE_NONE;
Expand Down

0 comments on commit 3280735

Please sign in to comment.