[KNotification] method sendEvent() is not called.
-
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!