[KNotification] method sendEvent() is not called.



  • Hello.
    Maybe somebody knows the answer to my question.
    I have a problem.
    I need to add to popup notify a few buttons to push on to be performed some action.
    Having studied the docks, I realized, that I needed the following methods:
    setActions(), setWidget(), sendEvent();
    However, upon the occurrence of a particular action, the method sendEvent() does not cause notify into standart KDE "recent notifications".
    Or is there another way to add the button to popup notification.
    Can you, please, tell me what's wrong.



  • Have you create a configuration file which specifies the events for your application?



  • Sorry, I did not get the question. What do you want to achieve?
    Why do you neet sendEvent?



  • I think he's using the class KNotification, from KDE library, which has a method sendEvent() that shows the notification. But it needs a configuration file which defines the events of the application, and the action to perform when one event is triggered (such as popup a widget, display a notification from the system tray, play sound, and so on).



  • I need to pop-up notification was provided a choice of some action and depending on what action should be chosen should be carried out some piece of code.

    If this can be done via the config. –°ould you show how to describe it?



  • If you are using KDE libraries you can refer to the following class documentation:
    http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKNotification.html#_details
    As you can see, you have to create a notifyrc file and insert there your events which can be fired.
    After that you have to create a KNotification object with one of the event name that you specified in that file, and call its sendEvent() after setting up something (such as action list, widget, and signal/slot connections between activated actions and your widget slots).



  • I can not understand how I relate the parameters in the config file with variables in the application. I have to specify the path to the config? or he has to cling to my program, if I put the config in
    / usr / share / apps / appname / appname.notifyrc?
    example from the documentation I have not Campiglio, said that the variables are not defined, but I think that they should be taken from the config.
    One more question, in order to establish a widget (ex. pushbutton) to pop notifay, I must declare it as something in the config or should I use the method setWidget ()? If the config - how i can do?
    Here is a code, without using the config:
    @
    KNotification * notification = new KNotification ("conflict");

    notification-> setText ("handling conflicts");
    notification-> setPixmap (trayIcon-> icon (). pixmap (64,64));
    notification-> setActions (QStringList (i18nc ("action: button", "Resume ")));
    notification-> setWidget (button);
    notification-> sendEvent ();
    @

    Tupla, show me, please, how to collaborate with the config.



  • Quoting from the docs

    bq. Your application should install a file called: $KDEDIR/share/apps/appname/appname.notifyrc
    You can do this with the following CMake command: install( FILES appname.notifyrc DESTINATION ${DATA_INSTALL_DIR}/appname))

    So you have to create your *.notifyrc file and put a line in your CMakeLists.txt to install that file (when you give command "make install").
    I don't understand the variables part, simply create a KNotification object, and in its constructor you pass the eventId, which is the event identifier that you previously specified in your *.notifyrc file.

    Step by step:

    1. Create a *.notifyrc file, fill it with your global information, context information and events, and add a line to your cmake file, in order to install it.
    2. Create a KNotification object when needed, giving as eventId one of the event you specified in your file (i.e., if you wrote [Event/newMail], the eventId is "newMail").
    3. Add an action list to your notification as you did in the previous post.
    4. Optionally set a widget which will be bound to the notification, using setWidget().
      Beware: the widget associated using setWidget() is not what you may think (not a button for triggering an action, for example).
      That widget is simply associated with the notification, and the notification can follow some behaviour (such as "close when the widget is activated"), that's the widget I'm talking about.
      An example is worth a thousand words:
      @
      // create notification and associate it with your widget
      KNotification * notification = new KNotification ("conflict", yourWidget);

    notification-> setText ("handling conflicts");
    notification-> setPixmap (trayIcon-> icon (). pixmap (64,64));
    notification-> setActions (QStringList (i18nc ("action: button", "Resume ")));
    // By doing this, when the action of the notification is activated your widget's slot will be called
    connect(notification, SIGNAL(activated(unsigned int)), yourWidget, SLOT(handleConflicts()));
    notification-> sendEvent ();
    @
    Hope now it's clear ;-)



  • This is notify.notifyrc file:
    @
    [Global]
    IconName=Filename
    Comment=Friendly Name of app
    [Context/group]
    Name=Group name
    Comment=The name of the group for contacts
    [Event/conflict]
    Name=Conflict
    Comment=You have got a new email
    Contexts=group
    Action=Popup
    @
    After compiling my project, when i'll try opened the application the system give me following error:
    @
    (22998) KIconCache::Private::themeDirsChanged: Theme directory has been modified
    (22998) KToolInvocation::klauncher: klauncher not running... launching kdeinit
    kdeinit4: preparing to launch /usr/lib/libkdeinit4_klauncher.so
    klauncher(23003) kdemain: No DBUS session-bus found. Check if you have started the DBUS server.
    kdeinit4: Communication error with launcher. Exiting!
    startkdeinitlock(22998): Couldn't start knotify from knotify4.desktop: "KLauncher could not be reached via D-Bus. Error when calling start_service_by_desktop_path:
    Not connected to D-Bus server
    "
    @
    And i put my code:
    @
    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    QWidget *widget = new QWidget();
    QPushButton *button = new QPushButton("Button:Act", widget);
    button->setEnabled(true);
    KNotification *notification = new KNotification("conflict", widget);
    notification->setText("handling conflicts");
    notification->setActions(QStringList("Resume "));
    notification->setWidget(button);
    notification->sendEvent();
    return 0;
    }
    @
    I did not use method connect() to connect signal / slot.
    I think, that it can not be given such an error and besides, it should work without method connect().

    Tupla, Can you tell, that I had not right?



  • I see you use QApplication, I don't know if this is the problem, but I suggest to use KApplication, instead.
    Beside that, you have not called app.exec().
    Try to call KNotification::event(KNotification::Notification, "yourtext"), to see if standard notification work.



  • It's a bit tricky to find, but found a solution.
    If the notification works with the last instruction that I gave you, but not with your eventId, it's because you have to kill knotify4 and run kbuildsycoca4 before start your application (obviously your appname.notifyrc must be correctly installed, and everything already set up).



  • You are right, i forgot app.exec(). Now, standard notification is work.
    You are said:
    "obviously your appname.notifyrc must be correctly installed, and everything already set up"

    I set the appname.notifyrc as root, because when I start to install from a user, I have not access rights.
    Where can I find knotify4.desktop and I should just delete it, then start kbuildsycoca4?
    How I should correctly installed appname.desktop?



  • For everything to work you have to use KApplication, not QApplication (because the "appname" is given in main using KAboutData class).
    Example of main:
    @KAboutData about("appname", 0, ki18n("MyApp"), "1.0" /* version /, / for other parameters see KAboutData docs */);
    KCmdLineArgs::init(argc, argv, &about);
    KApplication app;

    MyMainWidget *widget = new MyMainWidget;
    widget->show();

    return app.exec();@
    Obviously, MyMainWidget is your main window class, code it as you like.
    If you create a "appname.notifyrc" file, write into it your events and install it with that CMake command, when you send an event in your code, a notification should be displayed.
    I didn't understand why you set your file as root, that command only installs it in your installation prefix.

    However, kill knotify4 (CTRL+Esc, search for knotify4 and kill it), then from a terminal run kbuildsycoca4.
    If it doesn't work again, try to copy appname.notifyrc in your main KDE prefix (should be /use/share/kde4/apps if you use kubuntu, for example) by creating a new directory named "appname", place your file in there. With this extreme way it has to work when you kill knotify4 and run kbuildsycoca4.



  • It worked, thanks.
    Only now I do not understand how it works:)
    If I write the line:
    @
    KAboutData about ("notify", 0, ki18n ("notify"), "1.0");
    @
    It works, despite the fact that my file - it's psnotify.notifyrc
    However, if I write the line:
    @
    KAboutData about ("psnotify", 0, ki18n ("psnotify"), "1.0");
    @
    It does not cause notice.

    I have to you one more question - where information can be read from the config?
    And where information can be read, if I deleted all the config files from the system? (Where a thread can sit in the cache)?



  • Mmm, I don't know, since I tried using the same name for application name in KAboutData and in the name of the notification file.

    Sorry, but I don't understand your question. Maybe you want to know where configuration files for your KDE application are stored and how to access to configuration data?



  • Yes, exactly :-)
    I use Mandriva Linux 2010 and i know that configuration files are in the /usr/local/share/apps/appname/appname.notifyrc
    and
    /usr/share/apps/appname/appname.notifyrc
    Could it be that they are stored in another location?



  • If you compile KDE from source, you should be able to specify the "prefix" where to install it, most commons are /usr/local, /usr/, or somewhere in your home directory if you don't want to have it system-wide (especially with KDE unstable branch).
    In /usr/local, which is your prefix, there are main configuration files. They contain the basic options and configuration for each application. When you first start a KDE application, configuration files are copied from your prefix into your home directory, so that you can customize them without touching the original files in /usr/local (also because you normal user don't have enough permissions). You home directory should be $HOME/.kde or $HOME/.kde4. The next time you start the same application, configuration are read both from your own config file in .kde or .kde4, and merged with other option in the "global" configuration file (in /usr/local).

    To access data in a configuration file (I'm talking about config file of your application, which you implemented) you have to use KConfig, KConfigGroup and other classes in your application. Also, you don't need to specify where to put your configuration file, KDE will create it in your home directory (again, .kde or .kde4), simply create a KConfig or KConfigGroup object, and read or write entry into your config file.



  • I did "logout" and when logged again, I discovered that notification not show.
    How can it be?



  • Where did you put your notifyrc file? Does it match the name of your application?



  • Thanks, it works, I understood.
    I want ask you, I have a small question: May I put default action in notify, if it had to disappeared and nobody choosing action?



  • Do you mean if the notification timeout expires and it disappears without having time to choose an action? You find it in "recent notification", next to the system tray. Or you can use Persistent flag, and close it manually when your code has been executed.



  • Yes-yes, you are right. But I was wondering whether the disappearance of notification perform the action by default, if you have not chosen any action.



  • Nope, I think the disappearance doesn't perform any action by default, you have to manually activate it.



  • Thanks, Tupla ^___^



  • You're welcome!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.