Ringhio Notifications ProgressBar Example

From wiki.amiga.org
Jump to navigation Jump to search

Introduction

This is a basic example in C of how to use the latest Ringhio Notifications to display a notification bubble displaying an incrementing progress bar.


It can be reused in many applications where the progress of a file operation can be monitored in the background by the user and does not need to be displayed in focus or inside a window.


The source code example below the progress bar gradually increments whilst the bubble remains open on screen. It requires the latest Ringhio Notifications and ProgressBar Gadget Class to be installed.

Screen Shot

ProgressBar Ringhio Test.png

Source Code

//
// Description:  Basic example source code on how to use new feature of displaying a 
// incrementing progress bar inside a Ringhio Notification bubble
// 
// Requirements: Ringhio Notifications v53.65 or later, ProgressBar.gadget v53.10 or later 
//
// Authors: G.Boesel and M.Tretene (19/03/2017) 
//
// To compile:
//
// gcc  ProgressBar_Ringhio_Test.c -o ProgressBar_Ringhio_Test -lauto -lamiga  
//

#include <dos/dos.h>
#include <stdio.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/arexx.h>
#include <proto/bsdsocket.h>
#include <classes/arexx.h>
#include <proto/arexx.h>
#include <proto/application.h>

#ifndef APPNOTIFY_DisplayTime
#define APPNOTIFY_DisplayTime   ( TAG_USER + 13 )
#endif

#ifndef APPNOTIFY_Percentage
#define APPNOTIFY_Percentage    ( TAG_USER + 14 )
#endif

struct ApplicationIFace *IApplication = NULL;
struct PrefsObjectsIFace *IPrefsObjects = NULL;

uint32 appID = 0 ;

void fonctionMessageRinghio(int PERCENT_VALUE)
{
	IApplication->Notify(appID,
		APPNOTIFY_Percentage, PERCENT_VALUE,
		TAG_END);
}

ULONG registerApplication()
{
	appID = IApplication->RegisterApplication("Test_Ringhio",
				REGAPP_URLIdentifier, "a-eon.com",
				REGAPP_Description, "Test Ringhio",
				REGAPP_UniqueApplication, TRUE,
				REGAPP_AllowsBlanker, TRUE,            
				REGAPP_HasPrefsWindow, FALSE,
				REGAPP_HasIconifyFeature, FALSE,
				REGAPP_NoIcon, FALSE,
				REGAPP_LoadPrefs, FALSE,
				TAG_DONE) ;

	return appID;  	
}

void unregisterApplication()
{
  IApplication->UnregisterApplication(appID, NULL);
}


int main(int argc,char **argv)
  {  

	ApplicationBase = IExec->OpenLibrary("application.library", 52) ;
	if (ApplicationBase)
	{	
	    IApplication  = (struct ApplicationIFace *)  IExec->GetInterface(ApplicationBase, "application", 2, NULL);
   		IPrefsObjects = (struct PrefsObjectsIFace *) IExec->GetInterface(ApplicationBase, "prefsobjects", 2, NULL);
   		registerApplication() ;
   	}
   	else
   	{
		printf("Unable to open ApplicationBase \n");
   		return 0 ;		    
   	} 

	if (appID > 0)
	{	
		// first msg to ringhio to open the progressbar

		IApplication->Notify(appID,
			APPNOTIFY_Title, "Test Ringhio",
			APPNOTIFY_Text, "downloadName",
			APPNOTIFY_ImageVertAlign, 1,
			APPNOTIFY_DisplayTime, TRUE,     
			APPNOTIFY_Percentage, 0,
			TAG_END);

		IDOS->Delay(50);

		int i = 0 ;

		for (i = 0 ; i < 2 ; i++)
		{
	  		int cpt = 0 ;

	  		for (cpt = 0 ;  cpt < 100 ; cpt++)
	  		{
				// msg to Ringhio to uopdate the progressbar
				fonctionMessageRinghio(cpt);	
				IDOS->Delay(5) ;
	  		}
	  	}

		// last msg to close the msg

		IApplication->Notify(appID,
			APPNOTIFY_Update, TRUE,
			TAG_END);

		unregisterApplication() ;
	}
		
	if (ApplicationBase)
	{
		IExec->DropInterface((struct Interface *)IPrefsObjects);
		IExec->DropInterface((struct Interface *)IApplication);
		IExec->CloseLibrary(ApplicationBase);
	}
}