Oh, that's wonderful.
I was able to add a right-click menu to the above C Code and also to add some new functions, that runs several applications. Also i do check inside this functions if the application is available. If not, it runs the RunScript for the use of the SFS.
That's pretty cool, since this was my first real "hack" ever on C Code.
@ 01micko
The tempicon application has been very helpful on that. I assume it will be alright, if i post my "hacked" Code here? I think it could be interesting to others and maybe someone will find a bug on this...
Code: Select all
//#############################################################################
// System Tray Application Starter
// Original C Code by 01micko
// Modified by RSH for the use of the LazY DNS - (D)ow(N)load (S)uite
// LazY DNS Wrapper 0.3
//#############################################################################
// to compile: gcc -o example example.c `pkg-config --libs --cflags gtk+-2.0`
//#############################################################################
// Include Files
#include <gtk/gtk.h>
#include <gdk/gdk.h>
// Icons
GdkPixbuf *a_pixbuf;
GtkStatusIcon *tray_icon;
// Error Check on File Open
GError *gerror = NULL;
// File and Filenames
FILE *fp;
char lazyfredname[37]="/usr/local/LazY-FReD/set_preferences";
char lazyreconame[30]="/usr/local/LazY-FReD/LazYReCo";
char lazymaidname[30]="/usr/local/LazY-MAID/LazYMAID";
//#############################################################################
// Right-Click Functions called from Menu
//#############################################################################
// Run LazY FReD
static run_lazy_fred(){
fp = fopen(lazyfredname,"r");
if(fp == NULL)
{
system("/root/.my-sfs-scripts/LP2_LazY-FReD-1.0.3.sfs.Scripts/LP2_LazY-FReD-1.0.3.sfs.LazY-FReD.run.sh &");
return 1;
}
system("/usr/local/LazY-FReD/set_preferences &");
}
// Run LazY ReCo
static run_lazy_reco(){
fp = fopen(lazyreconame,"r");
if(fp == NULL)
{
system("/root/.my-sfs-scripts/LP2_LazY-FReD-1.0.3.sfs.Scripts/LP2_LazY-FReD-1.0.3.sfs.LazY-ReCo.run.sh &");
return 1;
}
system("/usr/local/LazY-FReD/LazYReCo &");
}
// Run LazY MAID
static run_lazy_maid(){
fp = fopen(lazymaidname,"r");
if(fp == NULL)
{
system("/root/.my-sfs-scripts/LP2_LazY-MAID-1.0.2.sfs.Scripts/LP2_LazY-MAID-1.0.2.sfs.LazY-MAID.run.sh &");
return 1;
}
system("/usr/local/LazY-MAID/LazYMAID &");
}
//#############################################################################
// Left-Click Function on System Tray Icon
//#############################################################################
// Run LazY DNS if left-clicked on icon
static tray_icon_on_click(GtkStatusIcon *status_icon,
gpointer user_data)
{
system("/usr/local/LazY-DNS/LazYDNS");
}
//#############################################################################
// Right-Click-Menu Functions
//#############################################################################
// Menu Entry LazY DNS
void view_popup_menu_run_lazy_dns (GtkWidget *menuitem, gpointer user_data)
{
system("/usr/local/LazY-DNS/LazYDNS &");
}
// Menu Entry LazY FReD
void view_popup_menu_run_lazy_fred (GtkWidget *menuitem, gpointer user_data)
{
run_lazy_fred();
}
// Menu Entry LazY ReCo
void view_popup_menu_run_lazy_reco (GtkWidget *menuitem, gpointer user_data)
{
run_lazy_reco();
}
// Menu Entry LazY MAID
void view_popup_menu_run_lazy_maid (GtkWidget *menuitem, gpointer user_data)
{
run_lazy_maid();
}
// Menu Entry Quit
void view_popup_menu_quit (GtkWidget *menuitem, gpointer user_data)
{
gtk_main_quit();
}
// nothing
static view_popup_menu_dummy (GtkWidget *menuitem, gpointer user_data)
{
return 2;
}
//#############################################################################
// Menu Function
//#############################################################################
// Right-Click on System Tray Icon
void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data)
{
GtkWidget *menu, *menuitem;
menu = gtk_menu_new();
menuitem = gtk_menu_item_new_with_label("LazY DNS 0.3 Download Suite");
g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_run_lazy_dns, status_icon);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new();
//g_signal_connect(menuitem, "none", (GCallback) view_popup_menu_dummy, status_icon);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new_with_label("LazY FReD Free Repository Downloader");
g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_run_lazy_fred, status_icon);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new_with_label("LazY ReCo Repository Collector");
g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_run_lazy_reco, status_icon);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new_with_label("LazY MAID Murga-Linux Attachment-Index Downloader");
g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_run_lazy_maid, status_icon);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new();
//g_signal_connect(menuitem, "none", (GCallback) view_popup_menu_dummy, status_icon);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new_with_label("LazY DNS 0.3 Beenden");
g_signal_connect(menuitem, "activate", (GCallback) view_popup_menu_quit, status_icon);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show_all(menu);
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, gdk_event_get_time(NULL));
}
//#############################################################################
// System Tray Icon
//#############################################################################
// Create Tray Icon
static GtkStatusIcon *create_tray_icon()
{
tray_icon = gtk_status_icon_new();
g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL);
g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL);
a_pixbuf=gdk_pixbuf_new_from_file("/usr/local/LazY-DNS/icons/lazydns24.png",&gerror);
gtk_status_icon_set_from_pixbuf(tray_icon,a_pixbuf);
gtk_status_icon_set_tooltip(tray_icon, "LazY DNS 0.3 Download Suite");
gtk_status_icon_set_visible(tray_icon, TRUE);
return tray_icon;
}
//#############################################################################
// Main Program Functions
//#############################################################################
// Main Program
int main(int argc, char **argv)
{
gtk_init(&argc, &argv);
create_tray_icon();
gtk_main();
return 0;
}
//#############################################################################
// End of LazY DNS Wrapper
//#############################################################################
I have also written a script to compile this C Code. If you click the script it wants to compile example.c inside the script's directory. But you can drag & drop a C Code file from any else directory onto this script and it compiles the dropped file. So you can rename this or the above example.c and compile it using a new name for it.
This script is only for the use on the above posted C Code files!
Code: Select all
#!/bin/sh
FindExec="gcc"
file_to_compile="$1"
f_t_c="`basename $file_to_compile`"
d_t_c="`dirname $file_to_compile`"
nlen="`echo ${#f_t_c}`"
o_f=${f_t_c:0:$nlen-2}
Titel="Compiling $f_t_c"
if [ "$(which $FindExec)" ]; then
echo "C Compiler already loaded"
else
Xdialog --title "$Titel" --wrap --screen-center --center --ok-label "Load" --cancel-label "Do ot load" --yesno "\nC Compiler missing. \n\nUYou have to load the devx.sfs of your puppy." 0 0
exit 1
#if [ "$?" = "0" ]; then
# sfs_load --cli --quiet Your_DevX_Here.sfs
#fi
fi
if [ "$(which $FindExec)" ]; then
if [ "$file_to_compile" = "" ]; then
# compile example.c
lxterminal -e gcc -o example example.c `pkg-config --libs --cflags gtk+-2.0`
else
# compile file dropped on the script
cd $d_t_c
lxterminal -e gcc -o "$o_f" "$f_t_c" `pkg-config --libs --cflags gtk+-2.0`
fi
fi
exit 0