LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-27-2014, 09:18 AM   #1
RavenLX
Member
 
Registered: Oct 2004
Posts: 98

Rep: Reputation: 15
Question How do I get a desktop notification action to run?


I am writing a perl script which I want to make it send a desktop notification. It polls for changes somewhere and then it will create a text file of changes. Next it will send a notification to the desktop (I'm using KDE, actually). In the notification should be a clickable button that when clicked, the default text editor should appear with the text file in it. Note I am using "kate" hard coded right now because I don't yet know how to detect the default text editor.

What happens with my code is Kate appears with the text in it first, while giving an error (see code comments below) and then after closing Kate the notification and button appears. Clicking the button does nothing.

I'm doing this in perl because I'm best at perl and also because I'm going to use this as a weekly cron job to poll and parse a web site, compare with data I have and then alert me if there was new data and give me a text list of the new data (thus the See List button).

Below is what I have so far. Can someone instruct me on how I can fix this? I've used Google and can't find any examples of proper usage of add_action.
Code:
#!/usr/bin/perl
# Distro: SolydK (Debian Testing (Jesse) based)
# KDE 4.13.3
# Depenencies installed:
# gir1.2-appindicator3-0.1
# gir1.2-notify-0.7
# libnotify
# perl-glib-object-introspection
 
use Glib::Object::Introspection;

Glib::Object::Introspection->setup (
	basename => 'Notify',
	version => '0.7',
	package => 'Notify');
Notify->init;
my $popupnote = Notify::Notification->new("New Items Detected", "There are new items for your review.", "dialog-information");

# The add_action below pops up Kate with the text file in it first, and gives this error:
# QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.
# Then after closing Kate the desktop notification will pop up with "See List" button appears.
# The See List button does nothing when clicked.
$popupnote->add_action("actionList", "See List", "default", eval(system("kate ~/Temp/Test.txt")));

$popupnote->show;
 
Old 09-27-2014, 11:08 AM   #2
RavenLX
Member
 
Registered: Oct 2004
Posts: 98

Original Poster
Rep: Reputation: 15
Lightbulb

I found the solution. I got it working but still can't get the error referenced in the comments to go away. Note that I'm now using a different library. I uninstalled the gir libraries (and this works without them) and the other libraries were installed by default so I left them in. The only other library I had to add was 'libgtk2-notify-perl'.
Code:
#!/usr/bin/perl
# Distro: SolydK (Debian Testing (Jesse) based)
# KDE 4.13.3

# Depenencies installed:
# libgtk2-notify-perl

# This works, but still there's this error in the console:
#QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.

use Gtk2::Notify -init, 'Multi Actions';

my $popupnote = Gtk2::Notify->new(
        'A new message!',
        'This is a new message.'
);
$popupnote->add_action('list', 'See List', \&do_action);
$popupnote->show;

Gtk2->main;

sub do_action {
    my ($popup, $action) = @_;
    system("kate ~/Temp/Test.txt");
    $popup->close;
    Gtk2->main_quit;
}
 
Old 09-27-2014, 11:43 AM   #3
RavenLX
Member
 
Registered: Oct 2004
Posts: 98

Original Poster
Rep: Reputation: 15
I just found more information on the QDBusConnection errors:

http://www.archivum.info/ubuntu-bugs...misbehave.html

Basically it seems like it's only a warning that is in the console and can safely be ignored.
 
  


Reply

Tags
desktoplinux, notifications, perl



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: GLib 2.37.5 Implements the Desktop Action Specification LXer Syndicated Linux News 0 08-19-2013 06:50 AM
Remote Desktop notification adrianlarsson Debian 1 07-11-2008 04:19 PM
which command is resposible for logoff action though desktop? redhotiron Linux - Desktop 2 07-22-2007 09:12 AM
Installed Mozilla and No More Desktop Link Action olias Linux - Software 7 04-05-2003 08:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration