<commit_before>/* This file is part of the KDE libraries
   Copyright (C) 2000 <NAME> <<EMAIL>>
                 2000 <NAME> <<EMAIL>>
		 2000,2003 <NAME> <<EMAIL>>
		 2003 <NAME> <<EMAIL>>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include "kopetenotifyclient.h"

#include <qfile.h>
#include <qlayout.h>
#include <qsignal.h>
#include <qvbox.h>

#include <dcopclient.h>
#include <kactivelabel.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kdeversion.h>
#include <kiconloader.h>
#include <klocale.h>
#if KDE_IS_VERSION( 3, 1, 90 )
#include <kmacroexpander.h>
#endif
#include <kmessagebox.h>
#include <kpassivepopup.h>
#include <kprocess.h>
#include <kwin.h>

static const char daemonName[] = "knotify";

static int notifyBySound( const QString &filename , const QString &appname, int uniqueId )
{
  if (!kapp) return 0;

  DCOPClient *client=kapp->dcopClient();
  if (!client->isAttached())
  {
    client->attach();
    if (!client->isAttached())
      return 0;
  }

  if ( !KNotifyClient::startDaemon() )
      return 0;


  QByteArray data;
  QDataStream ds(data, IO_WriteOnly);


#if 0   //TODO: when knotify support it, use this method insteads of the following
  ds << filename << appname << uniqueId;
  if ( client->send(daemonName, "Notify", "notifyBySound(QString,QString,int)", data) )
#elif KDE_IS_VERSION( 3, 1, 90 )
  ds << QString::null << appname << QString::null << filename << QString::null << 1 << KNotifyClient::Default << 0 << uniqueId;
  if ( client->send(daemonName, "Notify", "notify(QString,QString,QString,QString,QString,int,int,int,int)", data) )
      return uniqueId;
#else
  ds << QString::null << appname << QString::null << filename << QString::null << 1 << KNotifyClient::Default << 0 ;
  if ( client->send(daemonName, "Notify", "notify(QString,QString,QString,QString,QString,int,int,int)", data) )
      return uniqueId;
#endif

  return 0;
}

static bool notifyByMessagebox(const QString &text, int level, WId winId, const KGuiItem &action,
		QObject* receiver , const char* slot)
{
    // ignore empty messages
    if ( text.isEmpty() )
	return false;

    if(!receiver || !slot) {
	// display message box for specified event level
		switch( level ) {
		default:
#if KDE_IS_VERSION( 3, 1, 90 )
		case KNotifyClient::Notification:
			KMessageBox::informationWId( winId, text, i18n( "Notification" ) );
			break;
		case KNotifyClient::Warning:
			KMessageBox::sorryWId( winId, text, i18n( "Warning" ) );
			break;
		case KNotifyClient::Error:
			KMessageBox::errorWId( winId, text, i18n( "Error" ) );
			break;
		case KNotifyClient::Catastrophe:
			KMessageBox::errorWId( winId, text, i18n( "Fatal" ) );
			break;
#else
		case KNotifyClient::Notification:
			KMessageBox::information( 0, text, i18n( "Notification" ) );
			break;
		case KNotifyClient::Warning:
			KMessageBox::sorry( 0, text, i18n( "Warning" ) );
			break;
		case KNotifyClient::Error:
			KMessageBox::error( 0, text, i18n( "Error" ) );
			break;
		case KNotifyClient::Catastrophe:
			KMessageBox::errorWId( 0, text, i18n( "Fatal" ) );
			break;
#endif
		}
    } else { //we may show the specific action button
		int result=0;
		QSignal signal;
		signal.connect(receiver, slot);
		switch( level ) {
		default:
		case KNotifyClient::Notification:
			result = KMessageBox::questionYesNo(0, text, i18n( "Notification" ), action, KStdGuiItem::cancel(), QString::null, false );
			break;
		case KNotifyClient::Warning:
			result = KMessageBox::warningYesNo( 0, text, i18n( "Warning" ), action, KStdGuiItem::cancel(), QString::null, false );
			break;
		case KNotifyClient::Error:
			result = KMessageBox::warningYesNo( 0, text, i18n( "Error" ), action, KStdGuiItem::cancel(), QString::null, false );
			break;
		case KNotifyClient::Catastrophe:
			result = KMessageBox::warningYesNo( 0, text, i18n( "Fatal" ), action, KStdGuiItem::cancel(), QString::null, false );
			break;
	}
	if(result==KMessageBox::Yes)
		signal.activate();
    }

    return true;
}
<commit_msg>compile on kde 3.1, probably not the only commit needed to make kopete compile on kde 3.1<commit_after>/* This file is part of the KDE libraries
   Copyright (C) 2000 <NAME> <<EMAIL>>
                 2000 <NAME> <<EMAIL>>
		 2000,2003 <NAME> <<EMAIL>>
		 2003 <NAME> <<EMAIL>>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include "kopetenotifyclient.h"

#include <qfile.h>
#include <qlayout.h>
#include <qsignal.h>
#include <qvbox.h>

#include <dcopclient.h>
#include <kactivelabel.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kdeversion.h>
#include <kiconloader.h>
#include <klocale.h>
#if KDE_IS_VERSION( 3, 1, 90 )
#include <kmacroexpander.h>
#endif
#include <kmessagebox.h>
#include <kpassivepopup.h>
#include <kprocess.h>
#include <kwin.h>

static const char daemonName[] = "knotify";

static int notifyBySound( const QString &filename , const QString &appname, int uniqueId )
{
  if (!kapp) return 0;

  DCOPClient *client=kapp->dcopClient();
  if (!client->isAttached())
  {
    client->attach();
    if (!client->isAttached())
      return 0;
  }

  if ( !KNotifyClient::startDaemon() )
      return 0;


  QByteArray data;
  QDataStream ds(data, IO_WriteOnly);


#if 0   //TODO: when knotify support it, use this method insteads of the following
  ds << filename << appname << uniqueId;
  if ( client->send(daemonName, "Notify", "notifyBySound(QString,QString,int)", data) )
#elif KDE_IS_VERSION( 3, 1, 90 )
  ds << QString::null << appname << QString::null << filename << QString::null << 1 << KNotifyClient::Default << 0 << uniqueId;
  if ( client->send(daemonName, "Notify", "notify(QString,QString,QString,QString,QString,int,int,int,int)", data) )
      return uniqueId;
#else
  ds << QString::null << appname << QString::null << filename << QString::null << 1 << KNotifyClient::Default << 0 ;
  if ( client->send(daemonName, "Notify", "notify(QString,QString,QString,QString,QString,int,int,int)", data) )
      return uniqueId;
#endif

  return 0;
}

static bool notifyByMessagebox(const QString &text, int level, WId winId, const KGuiItem &action,
		QObject* receiver , const char* slot)
{
		// ignore empty messages
		if ( text.isEmpty() )
	return false;

	if(!receiver || !slot)
	{
	// display message box for specified event level
		switch( level )
		{
		default:
#if KDE_IS_VERSION( 3, 1, 90 )
		case KNotifyClient::Notification:
			KMessageBox::informationWId( winId, text, i18n( "Notification" ) );
			break;
		case KNotifyClient::Warning:
			KMessageBox::sorryWId( winId, text, i18n( "Warning" ) );
			break;
		case KNotifyClient::Error:
			KMessageBox::errorWId( winId, text, i18n( "Error" ) );
			break;
		case KNotifyClient::Catastrophe:
			KMessageBox::errorWId( winId, text, i18n( "Fatal" ) );
			break;
#else
		case KNotifyClient::Notification:
			KMessageBox::information( 0, text, i18n( "Notification" ) );
			break;
		case KNotifyClient::Warning:
			KMessageBox::sorry( 0, text, i18n( "Warning" ) );
			break;
		case KNotifyClient::Error:
			KMessageBox::error( 0, text, i18n( "Error" ) );
			break;
		case KNotifyClient::Catastrophe:
			KMessageBox::error( 0, text, i18n( "Fatal" ) );
			break;
#endif
		}
	}
	else
	{ //we may show the specific action button
		int result=0;
		QSignal signal;
		signal.connect(receiver, slot);
		switch( level )
		{
		default:
		case KNotifyClient::Notification:
			result = KMessageBox::questionYesNo(0, text, i18n( "Notification" ), action, KStdGuiItem::cancel(), QString::null, false );
			break;
		case KNotifyClient::Warning:
			result = KMessageBox::warningYesNo( 0, text, i18n( "Warning" ), action, KStdGuiItem::cancel(), QString::null, false );
			break;
		case KNotifyClient::Error:
			result = KMessageBox::warningYesNo( 0, text, i18n( "Error" ), action, KStdGuiItem::cancel(), QString::null, false );
			break;
		case KNotifyClient::Catastrophe:
			result = KMessageBox::warningYesNo( 0, text, i18n( "Fatal" ), action, KStdGuiItem::cancel(), QString::null, false );
			break;
		}

		if(result==KMessageBox::Yes)
			signal.activate();
	}

	return true;
}

{'fraction_non_alphanumeric': 0.13275566966195979, 'fraction_numerical': 0.019469405220367993, 'mean_word_length': 4.299886621315193, 'pattern_counts': {'":': 0, '<': 139, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6937897', 'n_tokens_mistral': 3402, 'n_tokens_neox': 3059, 'n_words': 924}