Source Code (Use browser search to find items of interest.)

Class Index

kdelibs'KNotify (./kdelibs/arts/knotify/knotify.h:29)

class KNotify : public QObject, DCOPObject
{
Q_OBJECT
K_DCOP

public:
	KNotify();
	virtual ~KNotify() {}

protected:
k_dcop:
	void notify(const QString &event, const QString &fromApp,
                         const QString &text, QString sound, QString file,
                         int present);

protected:
	bool notifyBySound(const QString &sound);
	bool notifyByMessagebox(const QString &text);
	bool notifyByLogfile(const QString &text, const QString &file);
	bool notifyByStderr(const QString &text);
private:
	SimpleSoundServer_base *server;
};


kdelibs'KNotify::KNotify() (./kdelibs/arts/knotify/knotify.cpp:74)

KNotify::KNotify() : QObject(), DCOPObject("Notify")
{
	// obtain an object reference to the soundserver
	server = SimpleSoundServer_base::_fromString("global:Arts_SimpleSoundServer");
	if(!server)
		cerr << "artsd is not running, there will be no sound notifications.\n";
}


kdelibs'KNotify::notify() (./kdelibs/arts/knotify/knotify.cpp:82)

void KNotify::notify(const QString &event, const QString &fromApp,
                                  const QString &text, QString sound, QString file,
                                  int present)
{
	static bool eventRunning=true;
	
	if (event.length())
	{
		KConfig eventsfile(locate("data", fromApp+"/eventsrc"));
		eventsfile.setGroup(event);
	
		if (present==-1)
			present=eventsfile.readNumEntry("presentation", -1);
		if (present==-1)
			present=eventsfile.readNumEntry("default_presentation", 0);
		
		sound=eventsfile.readEntry("sound", 0);
		if (sound.isNull())
			sound=eventsfile.readEntry("default_sound", "");
			
		file=eventsfile.readEntry("logfile", 0);
		if (file.isNull())
			file=eventsfile.readEntry("default_logfile", "");
		
	}
	
	// Not sure if the QFile::is[[:alpha:]]{4,5}able() works yet!
	eventRunning=true;
	if ((present & KNotifyClient::Sound) /* && (QFile(sound).isReadable())*/)
		notifyBySound(sound);
	if (present & KNotifyClient::Messagebox)
		notifyByMessagebox(text);
	if (present & KNotifyClient::Logfile/* && (QFile(file).isWriteable())*/)
		notifyByLogfile(text, file);
	if (present & KNotifyClient::Stderr)
		notifyByStderr(text);
	eventRunning=false;
}


kdelibs'KNotify::notifyBySound() (./kdelibs/arts/knotify/knotify.cpp:121)

bool KNotify::notifyBySound(const QString &sound)
{
	QString f(sound);
	if (QFileInfo(sound).isRelative())
		f=locate("sounds", sound);

	if(server) server->play((const char *)f);
	
	return true;
}


kdelibs'KNotify::notifyByMessagebox() (./kdelibs/arts/knotify/knotify.cpp:132)

bool KNotify::notifyByMessagebox(const QString &text)
{
	QMessageBox *notification;
	notification = new QMessageBox(i18n("Notification"),
	                               text,
	                               QMessageBox::Information,
	                               QMessageBox::Ok | QMessageBox::Default,
	                               0, 0, 0, 0, false);

	notification->show();
	return true;
}


kdelibs'KNotify::notifyByLogfile() (./kdelibs/arts/knotify/knotify.cpp:145)

bool KNotify::notifyByLogfile(const QString &text, const QString &file)
{
	QFile f(file);
	if (!f.open(IO_WriteOnly | IO_Append)) return false;
	QTextStream t(&f);

	t<< "=======================================\n";
	t<< "KNotify: " << QDateTime::currentDateTime().toString() << '\n';
	t<< text<< "\n\n";
	f.close();
	return true;
}


kdelibs'KNotify::notifyByStderr() (./kdelibs/arts/knotify/knotify.cpp:158)

bool KNotify::notifyByStderr(const QString &text)
{
	QTextStream t(stderr, IO_WriteOnly);

	t<< "KNotify: " << QDateTime::currentDateTime().toString() << '\n';
	t<< text<< "\n\n";
	return true;
}