Exemple #1
0
CF_EXPORT SInt32 CFUserNotificationDisplayAlert(CFTimeInterval timeout, CFOptionFlags flags, CFURLRef iconURL, CFURLRef soundURL, CFURLRef localizationURL, CFStringRef alertHeader, CFStringRef alertMessage, CFStringRef defaultButtonTitle, CFStringRef alternateButtonTitle, CFStringRef otherButtonTitle, CFOptionFlags *responseFlags) {
    CHECK_FOR_FORK();
    CFUserNotificationRef userNotification;
    SInt32 retval = ERR_SUCCESS;
    CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    if (iconURL) CFDictionaryAddValue(dict, kCFUserNotificationIconURLKey, iconURL);
    if (soundURL) CFDictionaryAddValue(dict, kCFUserNotificationSoundURLKey, soundURL);
    if (localizationURL) CFDictionaryAddValue(dict, kCFUserNotificationLocalizationURLKey, localizationURL);
    if (alertHeader) CFDictionaryAddValue(dict, kCFUserNotificationAlertHeaderKey, alertHeader);
    if (alertMessage) CFDictionaryAddValue(dict, kCFUserNotificationAlertMessageKey, alertMessage);
    if (defaultButtonTitle) CFDictionaryAddValue(dict, kCFUserNotificationDefaultButtonTitleKey, defaultButtonTitle);
    if (alternateButtonTitle) CFDictionaryAddValue(dict, kCFUserNotificationAlternateButtonTitleKey, alternateButtonTitle);
    if (otherButtonTitle) CFDictionaryAddValue(dict, kCFUserNotificationOtherButtonTitleKey, otherButtonTitle);
    userNotification = CFUserNotificationCreate(kCFAllocatorSystemDefault, timeout, flags, &retval, dict);
    if (userNotification) {
        retval = CFUserNotificationReceiveResponse(userNotification, timeout, responseFlags);
        if (MACH_RCV_TIMED_OUT == retval) {
            retval = CFUserNotificationCancel(userNotification);
            if (responseFlags) *responseFlags = kCFUserNotificationCancelResponse;
        }
        CFRelease(userNotification);
    }
    CFRelease(dict);
    return retval;
}
Exemple #2
0
void System::ErrorBox(const std::string& title, const std::string& text) {
#if defined _WIN32
	// I dunno about this, but I'm not a win32 programmer.
	const char *ttl = title.c_str();
	const char *txt = text.c_str();
	LPCTSTR lttl = (LPCTSTR) ttl;
	LPCTSTR ltxt = (LPCTSTR) txt;
	MessageBox(NULL, ltxt, lttl, MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
#elif defined __APPLE__
    // http://macosx-programming.blogspot.co.uk/2011/09/message-box-using-corefoundation.html
    SInt32 nRes = 0;
    CFUserNotificationRef pDlg = NULL;
    const void* keys[] = { kCFUserNotificationAlertHeaderKey,
        kCFUserNotificationAlertMessageKey };
    const void* vals[] = {
        CFStringCreateWithCString(NULL, title.c_str(), kCFStringEncodingASCII),
        CFStringCreateWithCString(NULL, text.c_str(), kCFStringEncodingASCII)
    };
    CFDictionaryRef dict = CFDictionaryCreate(0, keys, vals,
                                              sizeof(keys)/sizeof(*keys),
                                              &kCFTypeDictionaryKeyCallBacks,
                                              &kCFTypeDictionaryValueCallBacks);
    pDlg = CFUserNotificationCreate(kCFAllocatorDefault, 0,
                                    kCFUserNotificationPlainAlertLevel,
                                    &nRes, dict);
#else
	std::cerr << "ERROR: " << title << ": " << text << std::endl;
#endif
}
Exemple #3
0
Alert *
Alert_create(AlertCallback * func,
	     void * arg1, void * arg2, char * title, char * message)
{
    Alert *			alert_p;
    CFUserNotificationRef 	alert = NULL;
    CFDictionaryRef 		dict = NULL;
    SInt32			error = 0;
    CFRunLoopSourceRef		rls = NULL;

    alert_p = malloc(sizeof(*alert_p));
    if (alert_p == NULL) {
	EAPLOG_FL(LOG_NOTICE, "malloc failed");
	return (NULL);
    }
    bzero(alert_p, sizeof(*alert_p));
    dict = make_alert_dict(title, message);
    if (dict == NULL) {
	EAPLOG_FL(LOG_NOTICE, "make_alert_dict failed");
	goto failed;
    }
    alert = CFUserNotificationCreate(NULL, 0, 0, &error, dict);
    if (alert == NULL) {
	EAPLOG_FL(LOG_NOTICE, "CFUserNotificationCreate failed, %d", error);
	goto failed;
    }
    rls = CFUserNotificationCreateRunLoopSource(NULL, alert, 
						Alert_response, 0);
    if (rls == NULL) {
	EAPLOG_FL(LOG_NOTICE, "CFUserNotificationCreateRunLoopSource failed");
	goto failed;
    }
    CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
    alert_p->notif = alert;
    alert_p->rls = rls;
    alert_p->func = func;
    alert_p->arg1 = arg1;
    alert_p->arg2 = arg2;
    LIST_INSERT_HEAD(S_AlertHead_p, alert_p, entries);
    my_CFRelease(&dict);
    return (alert_p);

 failed:
    free(alert_p);
    my_CFRelease(&dict);
    my_CFRelease(&alert);
    my_CFRelease(&rls);
    return (NULL);
}
Exemple #4
0
SInt32 CFUserNotificationDisplayNotice(CFTimeInterval timeout, CFOptionFlags flags, CFURLRef iconURL, CFURLRef soundURL, CFURLRef localizationURL, CFStringRef alertHeader, CFStringRef alertMessage, CFStringRef defaultButtonTitle) {
    CHECK_FOR_FORK();
    CFUserNotificationRef userNotification;
    SInt32 retval = ERR_SUCCESS;
    CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    if (iconURL) CFDictionaryAddValue(dict, kCFUserNotificationIconURLKey, iconURL);
    if (soundURL) CFDictionaryAddValue(dict, kCFUserNotificationSoundURLKey, soundURL);
    if (localizationURL) CFDictionaryAddValue(dict, kCFUserNotificationLocalizationURLKey, localizationURL);
    if (alertHeader) CFDictionaryAddValue(dict, kCFUserNotificationAlertHeaderKey, alertHeader);
    if (alertMessage) CFDictionaryAddValue(dict, kCFUserNotificationAlertMessageKey, alertMessage);
    if (defaultButtonTitle) CFDictionaryAddValue(dict, kCFUserNotificationDefaultButtonTitleKey, defaultButtonTitle);
    userNotification = CFUserNotificationCreate(kCFAllocatorSystemDefault, timeout, flags, &retval, dict);
    if (userNotification) CFRelease(userNotification);
    CFRelease(dict);
    return retval;
}
void error_print(char *error_message, char *error_extend) {

char message[2048];

  if(error_extend) {
    snprintf(message,sizeof(message),error_message,error_extend);
  } else {
    snprintf(message,sizeof(message),"%s",error_message);
  }
  fprintf(stderr,"%s\n",message); // print error to stderr every time
#ifdef USE_WIN
  MessageBox(0,message,"Foobillard++ Error",MB_OK);
#else
#ifdef __APPLE__
  // needs -framework CoreFoundation
  SInt32 nRes = 0;
  CFUserNotificationRef pDlg = NULL;
  const void* keys[] = { kCFUserNotificationAlertHeaderKey,
  kCFUserNotificationAlertMessageKey };
  const void* vals[] = {
  CFSTR("Foobillard++ Error"),
  CFStringCreateWithCString(NULL, message, kCFStringEncodingMacRoman)
  };
  if(!sys_get_fullscreen()) {
  // display a dialog window only if fullscreen is not active
  CFDictionaryRef dict = CFDictionaryCreate(0, keys, vals,
                  sizeof(keys)/sizeof(*keys),
                  &kCFTypeDictionaryKeyCallBacks,
                  &kCFTypeDictionaryValueCallBacks);
  pDlg = CFUserNotificationCreate(kCFAllocatorDefault, 0,
                       kCFUserNotificationPlainAlertLevel,
                       &nRes, dict);
  }
#else
  char *dialog_prog[] = {"zenity --error --text=\"%s\"","kdialog --error \"%s\"","xmessage -center %s"};
  char newmessage[2048];
  // display a dialog window only if fullscreen is not active
  if(dialog>=0 && dialog < 2 && !sys_get_fullscreen()) {
    snprintf(newmessage,sizeof(newmessage),dialog_prog[dialog],message);
    system(newmessage);
  }
#endif
#endif
}
bool XMacSystem::DisplayNotification( const VString& inTitle, const VString& inMessage, EDisplayNotificationOptions inOptions, ENotificationResponse *outResponse)
{
	CFOptionFlags flags = (inOptions & EDN_StyleCritical) ? kCFUserNotificationCautionAlertLevel : kCFUserNotificationPlainAlertLevel;

	CFStringRef cfIconFileName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), CFSTR("CFBundleIconFile"));
	CFURLRef cfIconURL = (cfIconFileName == NULL) ? NULL : CFBundleCopyResourceURL( CFBundleGetMainBundle(), cfIconFileName, NULL, NULL);

	CFMutableDictionaryRef dico = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

	if (cfIconURL != NULL && dico != NULL)
		CFDictionaryAddValue( dico,	kCFUserNotificationIconURLKey, cfIconURL);
	
	// kCFUserNotificationAlertHeaderKey is required
	if (inTitle.IsEmpty())
	{
		PutStringIntoDictionary( inMessage, dico, kCFUserNotificationAlertHeaderKey);
	}
	else
	{
		PutStringIntoDictionary( inTitle, dico, kCFUserNotificationAlertHeaderKey);
		PutStringIntoDictionary( inMessage, dico, kCFUserNotificationAlertMessageKey);
	}

	ENotificationResponse responseDefault = ERN_None;
	ENotificationResponse responseAlternate = ERN_None;
	ENotificationResponse responseOther = ERN_None;

	switch( inOptions & EDN_LayoutMask)
	{
		case EDN_OK_Cancel:
			if (inOptions & EDN_Default1)
			{
				CFDictionaryAddValue( dico, kCFUserNotificationDefaultButtonTitleKey, CFSTR("OK"));
				CFDictionaryAddValue( dico, kCFUserNotificationAlternateButtonTitleKey, CFSTR("Cancel"));
				responseDefault = ERN_OK;
				responseAlternate = ERN_Cancel;
			}
			else
			{
				CFDictionaryAddValue( dico, kCFUserNotificationAlternateButtonTitleKey, CFSTR("OK"));
				CFDictionaryAddValue( dico, kCFUserNotificationDefaultButtonTitleKey, CFSTR("Cancel"));
				responseDefault = ERN_Cancel;
				responseAlternate = ERN_OK;
			}
			break;

		case EDN_Yes_No:
			if (inOptions & EDN_Default1)
			{
				CFDictionaryAddValue( dico, kCFUserNotificationDefaultButtonTitleKey, CFSTR("Yes"));
				CFDictionaryAddValue( dico, kCFUserNotificationAlternateButtonTitleKey, CFSTR("No"));
				responseDefault = ERN_Yes;
				responseAlternate = ERN_No;
			}
			else
			{
				CFDictionaryAddValue( dico, kCFUserNotificationDefaultButtonTitleKey, CFSTR("No"));
				CFDictionaryAddValue( dico, kCFUserNotificationAlternateButtonTitleKey, CFSTR("Yes"));
				responseDefault = ERN_No;
				responseAlternate = ERN_Yes;
			}
			break; 
		
		case EDN_Yes_No_Cancel:
			if ((inOptions & EDN_DefaultMask) == EDN_Default1)
			{
				CFDictionaryAddValue( dico, kCFUserNotificationDefaultButtonTitleKey, CFSTR("Yes"));
				CFDictionaryAddValue( dico, kCFUserNotificationAlternateButtonTitleKey, CFSTR("No"));
				CFDictionaryAddValue( dico, kCFUserNotificationOtherButtonTitleKey, CFSTR("Cancel"));
				responseDefault = ERN_Yes;
				responseAlternate = ERN_No;
				responseOther = ERN_Cancel;
			}
			else if ((inOptions & EDN_DefaultMask) == EDN_Default2)
			{
				CFDictionaryAddValue( dico, kCFUserNotificationDefaultButtonTitleKey, CFSTR("No"));
				CFDictionaryAddValue( dico, kCFUserNotificationAlternateButtonTitleKey, CFSTR("Yes"));
				CFDictionaryAddValue( dico, kCFUserNotificationOtherButtonTitleKey, CFSTR("Cancel"));
				responseDefault = ERN_No;
				responseAlternate = ERN_Yes;
				responseOther = ERN_Cancel;
			}
			else
			{
				CFDictionaryAddValue( dico, kCFUserNotificationDefaultButtonTitleKey, CFSTR("Cancel"));
				CFDictionaryAddValue( dico, kCFUserNotificationAlternateButtonTitleKey, CFSTR("No"));
				CFDictionaryAddValue( dico, kCFUserNotificationOtherButtonTitleKey, CFSTR("Yes"));
				responseDefault = ERN_Cancel;
				responseAlternate = ERN_No;
				responseOther = ERN_Yes;
			}

		case EDN_Abort_Retry_Ignore:
			CFDictionaryAddValue( dico, kCFUserNotificationDefaultButtonTitleKey, CFSTR("Retry"));
			CFDictionaryAddValue( dico, kCFUserNotificationAlternateButtonTitleKey, CFSTR("Ignore"));
			CFDictionaryAddValue( dico, kCFUserNotificationOtherButtonTitleKey, CFSTR("Abort"));
			responseDefault = ERN_Retry;
			responseAlternate = ERN_Ignore;
			responseOther = ERN_Abort;
			break;

		case EDN_OK:
		default:
			responseDefault = ERN_OK;
	}

	SInt32 error = 0;
	CFUserNotificationRef refNotification = CFUserNotificationCreate( kCFAllocatorDefault, 0 /*CFTimeInterval timeout*/, flags, &error, dico);

	if ( (refNotification != NULL) && (outResponse != NULL) )
	{
		*outResponse = ERN_None;
		if (error == 0)
		{
			CFOptionFlags responseFlags = 0;
			SInt32 rCode = CFUserNotificationReceiveResponse( refNotification, 0 /*CFTimeInterval timeout*/, &responseFlags);
			if (testAssert( rCode == 0))	// "0 if the cancel was successful; a non-0 value otherwise."
			{
				switch( responseFlags & 0x3)
				{
					case kCFUserNotificationDefaultResponse:	*outResponse = responseDefault; break;
					case kCFUserNotificationAlternateResponse:	*outResponse = responseAlternate; break;
					case kCFUserNotificationOtherResponse:		*outResponse = responseOther; break;
					case kCFUserNotificationCancelResponse:		*outResponse = ERN_Timeout; break;
				}
			}
		}
	}

	if (refNotification != NULL)
		CFRelease( refNotification);

	if (cfIconURL != NULL)
		CFRelease( cfIconURL);

	if (dico != NULL)
		CFRelease( dico);

	return error == 0;
}
Exemple #7
0
static void _kextd_raise_security_notification(CFStringRef kextPath)
{
    CFMutableDictionaryRef alertDict = NULL;  // must release
    CFMutableArrayRef alertMessageArray = NULL; // must release
    CFURLRef iokitFrameworkBundleURL = NULL;  // must release
    SInt32 userNotificationError = 0;

    alertDict = CFDictionaryCreateMutable(
        kCFAllocatorDefault, 0,
        &kCFTypeDictionaryKeyCallBacks,
        &kCFTypeDictionaryValueCallBacks);
    if (!alertDict) {
        goto finish;
    }

    iokitFrameworkBundleURL = CFURLCreateWithFileSystemPath(
        kCFAllocatorDefault,
        CFSTR("/System/Library/Frameworks/IOKit.framework"),
        kCFURLPOSIXPathStyle, true);
    if (!iokitFrameworkBundleURL) {
        goto finish;
    }

    alertMessageArray = CFArrayCreateMutable(kCFAllocatorDefault, 0,
        &kCFTypeArrayCallBacks);
    if (!alertMessageArray) {
        goto finish;
    }

   /* This is the localized format string for the alert message.
    */
    CFArrayAppendValue(alertMessageArray,
        CFSTR("The system extension \""));
    CFArrayAppendValue(alertMessageArray, kextPath);
    CFArrayAppendValue(alertMessageArray,
        CFSTR("\" was installed improperly and cannot be used. "
              "Please try reinstalling it, or contact the product's vendor "
              "for an update."));

    CFDictionarySetValue(alertDict, kCFUserNotificationLocalizationURLKey,
        iokitFrameworkBundleURL);
    CFDictionarySetValue(alertDict, kCFUserNotificationAlertHeaderKey,
        CFSTR("System extension cannot be used."));
    CFDictionarySetValue(alertDict, kCFUserNotificationDefaultButtonTitleKey,
        CFSTR("OK"));
    CFDictionarySetValue(alertDict, kCFUserNotificationAlertMessageKey,
        alertMessageArray);

    gCurrentNotification = CFUserNotificationCreate(kCFAllocatorDefault,
        0 /* time interval */, kCFUserNotificationCautionAlertLevel,
        &userNotificationError, alertDict);
    if (!gCurrentNotification) {
        kextd_error_log(
            "error creating user notification (%d)", userNotificationError);
        goto finish;
    }

     gCurrentNotificationRunLoopSource = CFUserNotificationCreateRunLoopSource(
         kCFAllocatorDefault, gCurrentNotification,
         &kextd_handle_finished_notification, 5 /* FIXME: cheesy! */);
    if (!gCurrentNotificationRunLoopSource) {
        CFRelease(gCurrentNotification);
        gCurrentNotification = NULL;
    }
    CFRunLoopAddSource(gMainRunLoop, gCurrentNotificationRunLoopSource,
        kCFRunLoopDefaultMode);

finish:

    if (alertDict)               CFRelease(alertDict);
    if (alertMessageArray)       CFRelease(alertMessageArray);
    if (iokitFrameworkBundleURL) CFRelease(iokitFrameworkBundleURL);

    return;
}