/* Copyright 2007, 2008, 2009, 2010 Geyer Klaus This file is part of Cat'sEyE. Cat'sEyE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Cat'sEyE 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 General Public License for more details. You should have received a copy of the GNU General Public License along with Cat'sEyE. If not, see . */ #include #include #include #include //Verzeichnis Zeiger und DIR - Struktur #include "globalDefinitions.h" #include "helpers.h" #include "mytrace.h" #include "listitems.h" #include "Lists.h" #include "allInclude.h" extern GtkTextBuffer *g_TextBuffer_CommandHistory; void CursorToWait(GtkWidget *widget){ // GdkWindow *gdkwindow = GTK_WIDGET (win)->window; //gint x,y; //GdkWindow *gdkwindow = gdk_window_at_pointer(&x,&y); //GdkWindow *gdkwindow = gtk_widget_get_parent_window (Object->ScrollWindow); //(GtkWidget *)win //GdkWindow *gdkwindow = gtk_widget_get_root_window (VPanedForFileShelf); //2.2 //gtk_widget_get_window //2.14 /* GdkCursor* cursor; cursor = gdk_cursor_new(GDK_WATCH); //GDK_WATCH GDK_CLOCK gdk_window_set_cursor(gdkwindow, cursor); //set the cursor to clock while we are updating gdk_get_default_root_window() gdk_cursor_destroy(cursor); */ //As long as changing the mouse cursor does not work, we change the text in the Notebooktab // gtk_label_set_text(GTK_LABEL(Object->label),"please wait"); GdkWindow *gdkwindow = gtk_widget_get_parent_window (widget); if (gdkwindow != NULL){ GdkCursor* cursor; cursor = gdk_cursor_new(GDK_WATCH); //GDK_WATCH GDK_CLOCK gdk_window_set_cursor(gdkwindow, cursor); //set the cursor to clock while we are updating gdk_get_default_root_window() gdk_cursor_destroy(cursor); } } void CursorToNormal(GtkWidget *widget){ GdkWindow *gdkwindow = gtk_widget_get_parent_window (widget); gdk_window_set_cursor(gdkwindow, NULL); } double GetTimeMine(GTimeVal time){ return (double)time.tv_sec + (double)time.tv_usec*0.000001; } int ExchangeSpecialCharachterForXML (GString *gstrText){ //will echange all special characters like &, <, >, ä, ö .... to their XML companions TRACEIT(10,"ExchangeSpecialCharachterForXML start"); if (gstrText == NULL){ TRACEIT(10,"ExchangeSpecialCharachterForXML parameter NULL"); return -1; } /* & & ' ' < < > > " " Ä Ä Ö Ö Ü Ü ä ä ö ö ü ü ß ß */ char *cppKnownSpecials[] = { "&", "'", "<", ">", """, "Ä", "Ö", "Ü", "ä", "ö", "ü", "ß"}; int iKnwonSpectials = 12; GString *gstrEnemy = g_string_sized_new (2); GString *gstrNewString = g_string_sized_new (9); g_string_assign (gstrEnemy, "Ö"); g_string_assign (gstrNewString, "Ö"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, "Ü"); g_string_assign (gstrNewString, "Ü"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, "ä"); g_string_assign (gstrNewString, "ä"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, "ö"); g_string_assign (gstrNewString, "ö"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, "ü"); g_string_assign (gstrNewString, "ü"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, "ß"); g_string_assign (gstrNewString, "ß"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, "'"); g_string_assign (gstrNewString, "'"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, "<"); g_string_assign (gstrNewString, "<"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, ">"); g_string_assign (gstrNewString, ">"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, "\""); g_string_assign (gstrNewString, """); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); g_string_assign (gstrEnemy, "Ä"); g_string_assign (gstrNewString, "Ä"); exchangeNameWithValue(gstrText, gstrEnemy, gstrNewString); char *cpBuf = NULL; char *cpBuf2 = NULL; int iDoNotExchangeThis = 0; int iLocation = 0; int i; cpBuf = strstr (gstrText->str, "&"); while (cpBuf) { iDoNotExchangeThis = 0; for (i=0; istr; g_string_insert (gstrText, iLocation+1, "amp;"); } cpBuf = cpBuf + 1; cpBuf = strstr (cpBuf, "&"); } g_string_free (gstrEnemy, TRUE); g_string_free (gstrNewString, TRUE); TRACEIT(10,"ExchangeSpecialCharachterForXML end"); return 0; } int checkItemIsLink (const char *ccpItem){ //return: -1=error, 0=NoLink, 1=Link TRACEIT(10,"checkItemIsLink start"); if (NULL == ccpItem){ TRACEIT (2, "checkItemIsLink parameter NULL"); return -1; } struct FileAttributs attribs; GString *gstrName = g_string_new (ccpItem); GString *gstrPath = g_string_new (ccpItem); int iRet = 0; checkPathForLastCharOtherwise(gstrName); getLastStringInPath(gstrName); GetPathFromPathWithName(gstrPath, 1); fileAttributesGet( &attribs, gstrPath->str, gstrName->str); if (attribs.gstrLinkTarget){ g_string_free(attribs.gstrLinkTarget, TRUE); iRet = 1; } g_string_free (gstrName, TRUE); g_string_free (gstrPath, TRUE); TRACEIT(10,"checkItemIsLink start"); return iRet; } int manipulateCounter (int *iCounter, gboolean bCountUp, const char *ccpSource){ //CountUp = TRUE: iCount++ //CountUp = FALSE: iCount-- //Counter can not drop under 0 TRACEIT(10,"manipulateCounter start"); if (iCounter == NULL){ TRACEIT (2, "manipulateCounter parameter NULL"); return -1; } if (bCountUp){ (*iCounter)++; } else{ (*iCounter)--; } if (*iCounter < 0){ *iCounter = 0; //TRACEIT (2, "manipulateCounter droped below 0 from:"); //if (ccpSource != NULL){ // TRACEIT (2, ccpSource); //} } TRACEIT(10,"manipulateCounter end"); return 0; } int exchangeNameWithValue(GString *gstrText, GString *gstrEnemy, GString *NewString){ //gstrText holds the String in wich gstrEnemy is searched for and gstrEnemy will be exchanged by NewString TRACEIT(10,"exchangeNameWithValue start"); char *cStart; int iPosition=0; int iSize; int firstTime = 1; do { cStart = strstr(gstrText->str,gstrEnemy->str); if (cStart == NULL && firstTime==0){ break; } else if(firstTime == 1 && cStart==NULL){ TRACEIT(10,"exchangeNameWithValue end 1"); return 0; //EnemyString not found !!! unused Variable? } firstTime = 0; iSize = strlen(gstrEnemy->str); iPosition = 0; while( (gstrText->str)+iPosition != cStart){ iPosition++; } g_string_erase(gstrText,iPosition,iSize); g_string_insert(gstrText,iPosition,NewString->str); }while (cStart != NULL); TRACEIT(10,"exchangeNameWithValue end"); return 1; } GFile *getCorrectGFileTypeFromLocation(char *location, int *iType){ //decides if we have a Path, File or an uri stored in location //and if iType is not NULL, writes the type to it. //return: A GFile Object (UNREF WITH g_object_unref()) or NULL on error. // //iType: -1 no idea, 0=locale file, 1=localePath, 2=uri TRACEIT(10,"getCorrectGFileTypeFromLocation start"); if (location == NULL){ TRACEIT(10,"getCorrectGFileTypeFromLocation end, Parameter NULL"); return NULL; } int iMostProperlyLocale=-1; gboolean bTestRegular; gboolean bTestDir; gboolean bTestExists; GFile *gfilePo=NULL; int iIThinkItIs=-1; if(strlen(location)>=1){ if (location[0] == '/'){ iMostProperlyLocale=1; } else{ iMostProperlyLocale=0; } } bTestExists = g_file_test (location, G_FILE_TEST_EXISTS); bTestDir = g_file_test (location, G_FILE_TEST_IS_DIR); bTestRegular = g_file_test (location, G_FILE_TEST_IS_REGULAR); if (bTestDir && bTestExists){ iIThinkItIs=1; //PATH gfilePo = g_file_new_for_path(location); if (iType) *iType = 1; } else if (bTestRegular && bTestExists){ iIThinkItIs=0; //file gfilePo = g_file_new_for_path(location); if (iType) *iType = 0; } else if (iMostProperlyLocale == 0){ iIThinkItIs=2; //uri gfilePo = g_file_new_for_uri(location); if (iType) *iType = 2; } else{ if (iType) *iType = -1; } TRACEIT(10,"getCorrectGFileTypeFromLocation end"); return gfilePo; } int getRandomIntNumber(int iMin, int iMax){ //returns a random Number within iMin and iMax (including). //if iMin or iMax is -1, no borders are applied //return: -1 on error, randomNumber on success TRACEIT(10,"getRandomIntNumber start"); int randomNumber=-1; if ((iMin!=-1 || iMax!=-1) && iMin >= iMax){ TRACEIT(4,"getRandomIntNumber end, iMin>=iMax"); return -1; } //srand(time(NULL)); if (iMin == -1 || iMax == -1){ randomNumber = rand(); } else{ randomNumber = iMin + (int) ((iMax) * (rand()/(RAND_MAX+1.0))); } TRACEIT(10,"getRandomIntNumber end"); return randomNumber; } void BytesToHumanity(guint64 bytes, double *newBytes, int *iEPow, GString *gstrEPow){ //gets an amount of bytes and breaks them trough 1024 till its easy to read even for humans //iEPow will get the potential by ten by which the new bytes correspont (can be NULL) //gstrEPor will hold a string wich represents iEPow (can be NULL) // example: 4 512 376 344 bytes -> newBytes = 4.512 476 344, iEPow=3, gstrEPow = "GiB" // TRACEIT(10,"BytesToHumanity start"); if (newBytes == NULL){ TRACEIT(2,"BytesToHumanity end, Parameter NULL"); return; } int i=0; double dbuf = (double) bytes; //while ((dbuf / 1024 > 1000.0)){ while ((dbuf > 1000.0)){ dbuf /= 1024; i++; } //dbuf /= 1024; //i++; *newBytes = dbuf; if (iEPow){ *iEPow=i; } if (gstrEPow){ switch (i){ case 0: g_string_assign(gstrEPow, "Byte"); break; case 1: g_string_assign(gstrEPow, "KiB"); break; case 2: g_string_assign(gstrEPow, "MiB"); break; case 3: g_string_assign(gstrEPow, "GiB"); break; case 4: g_string_assign(gstrEPow, "TiB"); break; } } TRACEIT(10,"BytesToHumanity end"); } void BytesToHumanityString (guint64 bytes, GString *gstrBytesString, int decimalplaces){ //converts the bytes to a format humans can read easely //4567 -> "4.567 KiB" TRACEIT(10,"BytesToHumanityString start"); if (gstrBytesString == NULL){ TRACEIT(2,"BytesToHumanityString end, Parameter NULL"); } double newBytes; GString *gstrEPow = g_string_sized_new(10); BytesToHumanity(bytes,&newBytes,NULL, gstrEPow); g_string_printf(gstrBytesString, "%0.2f %s", newBytes, gstrEPow->str); //free(cbuf); g_string_free(gstrEPow, TRUE); TRACEIT(10,"BytesToHumanityString end"); } gboolean checkStringIsPath(char *cpPath){ TRACEIT(10,"checkStringIsPath start"); if (cpPath == NULL){ TRACEIT(2,"checkStringIsPath end, Parameter NULL"); return FALSE; } gboolean bRet=FALSE; bRet = g_file_test( cpPath, G_FILE_TEST_IS_DIR); TRACEIT(10,"checkStringIsPath end"); return bRet; } char *completionReturnFunction(GString *gstrString){ return gstrString->str; } void *GListFreeGStrings (gpointer data, gpointer user_data){ TRACEIT(10,"GListFreeGStrings start"); if (data == NULL){ TRACEIT(2,"GListFreeGStrings end, Parameter NULL"); return NULL; } GString *gstrBuf = (GString *)data; g_string_free(gstrBuf, TRUE); TRACEIT(10,"GListFreeGStrings end"); return NULL; } int completePath(char *cpText, char **ToComplete){ //ToComplete has to be freed !!! //return: -1:error, 0=all ready path, 1=completed but no directory, 2=completed valid directory TRACEIT(10,"completePath start"); if (cpText == NULL || ToComplete == NULL){ TRACEIT(2,"completePath end, parameter null"); return -1; } struct myLocationStruct locationStru; GString *gstrNames=g_string_sized_new(10); GString *gstrPath=g_string_sized_new(10); struct FileAttributs attribs; GList *listDirs=NULL; GCompletion *completion=NULL; g_string_assign(gstrPath, cpText); if (0 == GetPathFromPathWithName (gstrPath, 0)){ //0=Already Path g_string_free(gstrNames,TRUE); g_string_free(gstrPath,TRUE); TRACEIT(10,"completePath end"); return 0; } openLocation(gstrPath->str, &locationStru, FALSE, FALSE); checkPathForLastChar(gstrPath); while ( 1==getNextItemInLocation(&locationStru, gstrNames, FALSE, FALSE) ){ fileAttributesGet(&attribs, gstrPath->str, gstrNames->str); if (attribs.type_d==4 && strcmp(gstrNames->str, ".")!=0 && strcmp(gstrNames->str, "..")!=0){ g_string_prepend(gstrNames, gstrPath->str); listDirs = g_list_append(listDirs, g_string_new(gstrNames->str)); } if (attribs.gstrLinkTarget){ g_string_free(attribs.gstrLinkTarget, TRUE); } } closeLocation(&locationStru); if (listDirs){ completion = g_completion_new ( (GCompletionFunc) completionReturnFunction); g_completion_add_items (completion, listDirs); g_completion_complete (completion, cpText, ToComplete); g_completion_clear_items (completion); g_completion_free(completion); g_list_foreach(listDirs, (GFunc) GListFreeGStrings, NULL); g_list_free(listDirs); } g_string_free(gstrNames,TRUE); if (*ToComplete){ g_string_assign(gstrPath, *ToComplete); if (TRUE == checkStringIsPath(gstrPath->str)){ g_string_free(gstrPath,TRUE); TRACEIT(10,"completePath end"); return 2; //valid directory } } g_string_free(gstrPath,TRUE); TRACEIT(10,"completePath end"); return 1; //no directory //I thought I could use g_filename_completer_get_completion_suffix to complete the string in the Pathentrybox //but it did not work (I dont know why, did I something wrong in the code below?) /* if ( (event->keyval == GDK_Tab)){ GFilenameCompleter *completer = g_filename_completer_new (); char *cText=NULL; g_object_get(PathEntryBox[leftORright],"text",&cText,NULL); if (completer == NULL){ } g_filename_completer_set_dirs_only(completer, TRUE); gchar *cCompleted = g_filename_completer_get_completion_suffix (completer, cText); if (cText){ g_free(cText); } if (cCompleted){ g_free(cCompleted); } else{ } g_object_unref (completer); return TRUE; }*/ } gboolean scrollListStoreToName_Helper (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, struct AllInformationAllUseStruct *stru){ TRACEIT(10,"scrollListStoreToName_Helper start"); int *Column = (int *)stru->Info_2; char *NameToFind = (char *)stru->Info_3; gchar *Name=NULL; GtkTreeSelection *selection=NULL; gtk_tree_model_get(model, iter, *Column, &Name, -1); if (Name){ if (strcmp(Name,NameToFind)==0){ gtk_tree_view_scroll_to_cell ((GtkTreeView *)stru->Info_4,path,NULL,TRUE,0.0,0.0); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW((GtkTreeView *)stru->Info_4)); gtk_tree_selection_select_iter(selection, iter); g_free(Name); TRACEIT(10,"scrollListStoreToName_Helper ends"); return TRUE; } } if (Name) g_free(Name); TRACEIT(10,"scrollListStoreToName_Helper ends"); return FALSE; } int scrollListStoreToName(GtkTreeView *listView, GtkListStore *listStore, GString *NameToScroll, int ColumnToSearch){ TRACEIT(10,"scrollListStoreToName start"); struct AllInformationAllUseStruct stru; int Column = ColumnToSearch; stru.Info_2=(void *)&Column; stru.Info_3=(void *)NameToScroll->str; stru.Info_4=(void *)listView; gtk_tree_model_foreach(GTK_TREE_MODEL(listStore),(GtkTreeModelForeachFunc) scrollListStoreToName_Helper,&stru); TRACEIT(10,"scrollListStoreToName end"); return 1; } int getHomeDirectory(GString *HomeDir){ TRACEIT(10,"getHomeDirectory start"); char *buf=NULL; if (HomeDir == NULL){ TRACEIT(2,"getHomeDirectory Parameter NULL"); return -1; } buf = getenv("HOME"); g_string_assign(HomeDir, buf); TRACEIT(10,"getHomeDirectory end"); return 0; } void checkPathForLastChar(GString *Path){ TRACEIT(11,"checkPathForLastChar start"); if (Path->str[strlen(Path->str)-1] != '/'){ g_string_append_c(Path,'/'); } TRACEIT(11,"checkPathForLastChar ends"); } void checkPathForLastCharOtherwise(GString *Path){ TRACEIT(11,"checkPathForLastCharOtherwise start"); if (strlen(Path->str) >1){ if (Path->str[strlen(Path->str)-1] == '/'){ g_string_set_size(Path,strlen(Path->str)-1); } } TRACEIT(11,"checkPathForLastCharOtherwise ends"); } void cutSpacesFromGString(GString *ToCut){ TRACEIT(10,"cutSpacesFromGString start"); cutCharFromGString(ToCut, ' ',0); TRACEIT(10,"cutSpacesFromGString ends"); } void cutLeadingSpacesFromGString(GString *ToCut){ TRACEIT(10,"cutLeadingSpacesFromGString start"); cutCharFromGString(ToCut, ' ',1); TRACEIT(10,"cutLeadingSpacesFromGString ends"); } void cutTapsFromGString(GString *ToCut){ TRACEIT(10,"cutTapsFromGString start"); cutCharFromGString(ToCut, '\t',0); TRACEIT(10,"cutTapsFromGString ends"); } void cutCharFromGString(GString *ToCut, char thechar, int OnlyLeadingOnes){ TRACEIT(10,"cutCharFromGString start"); int i; for (i=0; istr); i++){ if (ToCut->str[i] == thechar){ g_string_erase(ToCut,i,1); i--; } else if (OnlyLeadingOnes == 1){ return; } } TRACEIT(10,"cutCharFromGString end"); } void getLastStringInPath(GString *Path){ //removes the path and leaves the single name TRACEIT(10,"getLastStringInPath start"); GString *gstrbuf = g_string_new(Path->str); if (strcmp(Path->str,"/")==0){ g_string_free(gstrbuf,TRUE); return; } checkPathForLastCharOtherwise(gstrbuf); char *buf = strrchr(Path->str,'/'); if (buf == NULL){ TRACEIT(9,"getLastStringInPath ends NO"); g_string_free(gstrbuf,TRUE); return; } buf++; if (buf == '\0'){ TRACEIT(3,"getLastStringInPath ends SHOULD NEVER BE"); g_string_free(gstrbuf,TRUE); return; } g_string_assign(Path,buf); g_string_free(gstrbuf,TRUE); TRACEIT(10,"getLastStringInPath ends"); } int GetPathFromPathWithName(GString *PathAndName, int iDoIt){ //if iDoIt == 1, then the last string will be cut off wether or not the string in PathAndName is allready a path (ending /) //it iDoIt == 0, then this fuctions does nothing when the last char in PathAndName is a / //return: -1: Error, 0: already path, 1: Path written to PathAndName // TRACEIT(10,"GetPathFromPathWithName start"); if (PathAndName == NULL){ TRACEIT(10,"GetPathFromPathWithName end 1"); return -1; } GString *gstrBuf = g_string_new(PathAndName->str); if ( iDoIt == 0 && (gstrBuf->str)[strlen(gstrBuf->str)-1]=='/'){ //last char in PathAndName is a /, so it is all ready a path. g_string_free(gstrBuf, TRUE); return 0; } getLastStringInPath(gstrBuf); g_string_truncate(PathAndName, strlen(PathAndName->str)-strlen(gstrBuf->str)-1); if (strlen(PathAndName->str) == 0){ //we are in the root directory g_string_assign(PathAndName, "/"); } g_string_free(gstrBuf, TRUE); TRACEIT(10,"GetPathFromPathWithName end"); return 1; } void cutStringToNChars(GString *Text,int Size){ TRACEIT(10,"cutStringToNChars start"); if (strlen(Text->str)<=Size){ TRACEIT(10,"cutStringToNChars ends"); return; } g_string_truncate(Text,Size); g_string_append(Text, "..."); TRACEIT(10,"cutStringToNChars ends"); } void cleverCutStringToNChars(GString *ToCut, char *textToAddBetween, int Size){ //textToAddBetween can be NULL //devides ToCut into three sections. section 1 and 3 are half the size of Size and are put together to the new string, //which ends up not larger than Size in the case textToAddBetween is empty or NULL. //Section 1 comes from the beginning of ToCut while section 3 comes from the end. //Section 2 are the chars between section 1 and 3, and are deleted or exchanged by textToAddBetween. TRACEIT(10,"cleverCutStringToNChars start"); if (ToCut==NULL){ TRACEIT(10,"cleverCutStringToNChars ends, parameter NULL"); return; } if (strlen(ToCut->str)<=Size){ TRACEIT(10,"cleverCutStringToNChars ends, nothing to do"); return; } int wholeSize = strlen(ToCut->str); int pos = Size/2; int lenToCut = wholeSize-Size; g_string_erase (ToCut, pos, lenToCut); if (textToAddBetween != NULL){ g_string_insert (ToCut, pos+1, textToAddBetween); //not sure about the +1 here. } TRACEIT(10,"cleverCutStringToNChars end"); } int myTokenFunction (GString *gstrCompleteString, int TokenNumber, char *divider, GString *gstrToken){ //gstrToken must be a valid GString, we only assign a new string to it TRACEIT(10,"myTokenFunction start"); if (gstrCompleteString == 0 || divider==NULL || gstrToken == NULL){ TRACEIT(2,"myTokenFunction Parameter NULL"); return -1; } if (strstr(gstrCompleteString->str, divider) == 0){ g_string_assign(gstrToken, gstrCompleteString->str); TRACEIT(10,"myTokenFunction ends, no divider in string"); if (TokenNumber == 0){ return 1; } else{ return -1; } } int i; char *buf = malloc( sizeof(char *) * (strlen(gstrCompleteString->str)+2) ); char *start=NULL; char *end=NULL; strcpy(buf,gstrCompleteString->str); start = buf; for( i=0; istr); NewDPointer[OldCount]=NewString; } if (*gstrTPString != NULL) free(*gstrTPString); *gstrTPString = NewDPointer; TRACEIT(10,"AddNewGStringToDPointer end"); return 0; } int AddNewGUInt64ToPointerArray(guint64 **intArray, int OldCount, guint64 NewOne){ TRACEIT(10,"ToPointerArray start"); //allocates new memory and copies all entries from intArray and the NewOne to the new memory //and frees the old. int i; guint64 *NewPointer=NULL; NewPointer = malloc(sizeof(guint64) * (OldCount +1)); if (NewPointer == NULL){ TRACEIT(1,"ToPointerArray end, NewPointer, ERROR allocating memory"); return -1; } for (i=0;iwindow_state.type == 32){ //GDK_WINDOW_STATE = 32 gtk_window_deiconify ((GtkWindow *)user_data); } TRACEIT(10,"KeepWindowOnTop end"); return TRUE; } gboolean DeleteNotification (GtkWidget *widget, GdkEvent *event, gpointer user_data){ int *notification = (int *)user_data; *notification = 0; //dialog destroyed, this, however has nothing to do whith mainloop, but just destroys the widget return FALSE; //when this is TRUE, the widget will stay even when the user tries to close it. And because of our notification we d not close it either } GtkWidget *CreateMyWindow(char *title, GtkWindow *parent, int x, int y, gboolean bResizeable, gboolean bDestroyWithParent, gboolean bKeepOnTop, int *iDeleteNotification, gboolean bParentInteraction, gboolean bDeletable ){ //iDeleteNotification becomes 1 when window is running and 0 when it receives the destroy-signal TRACEIT(10,"CreateMyWindow start"); GtkWidget *dialog; dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); //gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog),TRUE); gtk_window_set_deletable((GtkWindow *)dialog,bDeletable); gtk_window_set_title((GtkWindow *)dialog,title); gtk_window_set_default_size((GtkWindow *)dialog,x,y); gtk_window_set_resizable((GtkWindow *)dialog,bResizeable); if (parent != NULL){ if (bParentInteraction){ gtk_window_set_modal((GtkWindow *)dialog,TRUE); //modal dialogs can be connected to other widgets with ..set_transient_for } //Modal windows prevent interaction with other windows in the same application gtk_window_set_transient_for((GtkWindow *)dialog,parent); //connects, in a way, the window with a parent window if (bDestroyWithParent){ gtk_window_set_destroy_with_parent((GtkWindow *)dialog, TRUE); } } if (bKeepOnTop) g_signal_connect (dialog,"window-state-event",G_CALLBACK(KeepWindowOnTop),(void *)dialog); if (iDeleteNotification){ //printf("CreateMyWindow Deletenotification enabled\n"); *iDeleteNotification = 1; //dialog valid //g_signal_connect (dialog,"destroy-event",G_CALLBACK(DeleteNotification),(void *)iDeleteNotification); //destroy-eventg hooks to the gdkwindow, but this may be destroyed from the widget automaticaly and so, no windget owns this window. That means that we do not receive this signal g_signal_connect (dialog,"delete-event",G_CALLBACK(DeleteNotification),(void *)iDeleteNotification); //his event hooks to the Widget } TRACEIT(10,"CreateMyWindow end"); return dialog; } GtkWidget *CreateMyDialog(char *title, GtkWindow *parent, int iButtons, char *respText1, int resp1, char *respText2, int resp2, char *respText3, int resp3, gboolean bResizeable){ TRACEIT(10,"CreateMyDialog start"); GtkWidget *dialog=NULL; if (iButtons == 1){ dialog = gtk_dialog_new_with_buttons(title,parent,GTK_DIALOG_DESTROY_WITH_PARENT,respText1,resp1,NULL); } else if (iButtons == 2){ dialog = gtk_dialog_new_with_buttons(title,parent,GTK_DIALOG_DESTROY_WITH_PARENT,respText1,resp1,respText2,resp2,NULL); } else if (iButtons == 3){ dialog = gtk_dialog_new_with_buttons(title,parent,GTK_DIALOG_DESTROY_WITH_PARENT,respText1,resp1,respText2,resp2,respText3,resp3,NULL); } //printf("creating dialog: %p, text1:%s--- text2:%s--- \n",dialog, respText1, respText2 ); gtk_window_set_deletable((GtkWindow *)dialog,FALSE); gtk_window_set_resizable((GtkWindow *)dialog,bResizeable); g_signal_connect (dialog,"window-state-event",G_CALLBACK(KeepWindowOnTop),(void *)dialog); TRACEIT(10,"CreateMyDialog end"); return dialog; } void MyMessageWidget(GtkWindow *parrent, char *title, char* message){ TRACEIT(10,"MyMessageWidget start"); TRACEIT(10,"MyMessageWidget, message:"); TRACEIT(10,message); GtkWidget *label; GtkWidget *dialog; GtkWidget *scrollwidget; //TRACEIT (5, "MyMessageWidget, message:"); //TRACEIT (5, message); dialog = CreateMyDialog(title,parrent,1,"Ok",GTK_RESPONSE_ACCEPT,"Stop execution",GTK_RESPONSE_REJECT,NULL, 0, TRUE); label = gtk_label_new(message); gtk_label_set_selectable ( (GtkLabel *)label, TRUE); gtk_label_set_line_wrap ( (GtkLabel *)label, TRUE); //gtk_window_set_default_size ( (GtkWindow *)dialog, 300, 200); gtk_window_resize ( (GtkWindow *)dialog, 300, 200); //gtk_window_set_resizable((GtkWindow *)dialog,FALSE); if (strlen(message)>100){ scrollwidget = gtk_scrolled_window_new(NULL,NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwidget),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); gtk_scrolled_window_add_with_viewport ( (GtkScrolledWindow *)scrollwidget, label); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),scrollwidget); } else{ gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),label); } gtk_widget_show_all(dialog); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); TRACEIT(10,"MyMessageWidget end"); } int MyEasyInputWidget (GtkWindow *parrent, char *title, char *text, GString *gstrUserText){ // opens a little dialog in which the user can give us a little text, think of the rename - dialog. // wahtever stays in gstrUserText is displayed in the input area as a predefined text. // return values: 0: User OK 1: User Cancel <0: Error TRACEIT(10,"MyEasyInputWidget start"); if (NULL == title || NULL==text || NULL==gstrUserText){ TRACEIT(3,"MyEasyInputWidget end, one or more parameters NULL"); return -1; } GtkWidget *dialog, *label; GtkWidget *EntryBox; GString *gstrbuf = g_string_sized_new(10); dialog = CreateMyDialog(title, parrent, 2, "Ok",GTK_RESPONSE_ACCEPT,"Cancel",GTK_RESPONSE_REJECT, NULL, 0, FALSE); label = gtk_label_new(text); gtk_misc_set_alignment ( (GtkMisc *)label, 0.0f, 0.0f); gtk_misc_set_padding ( (GtkMisc *)label, 4, 0); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),label); EntryBox = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(EntryBox),MAXENTRYBOX); gtk_editable_set_editable(GTK_EDITABLE(EntryBox),TRUE); g_signal_connect (EntryBox, "activate",G_CALLBACK(MyEasyInputWidget_EntryBoxActivate),dialog); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),EntryBox); g_object_set(EntryBox, "text", gstrUserText->str, NULL); gtk_widget_show_all(dialog); if (gtk_dialog_run(GTK_DIALOG(dialog))== GTK_RESPONSE_ACCEPT){ g_object_get(EntryBox, "text", gstrbuf, NULL); g_string_assign(gstrUserText,gstrbuf->str); gtk_widget_destroy(dialog); TRACEIT(10,"MyEasyInputWidget end 0"); g_string_free(gstrbuf, TRUE); return 0; } gtk_widget_destroy(dialog); TRACEIT(10,"MyEasyInputWidget end 1"); g_string_free(gstrbuf, TRUE); return 1; } int MyEasyInputWidget_Two (GtkWindow *parrent, char *title, char *text1, GString *gstrUserText1, char *text2, GString *gstrUserText2, char *button0, char *button1, char *button2, char *button3 ){ // opens a little dialog in which the user can give us a little text, think of the rename - dialog. // but this widget has up to two entry boxes where to enter text. // and up to 4 buttons // text1 must not be NULL // while gstrUserText1, text2 and gstrUserText2 may be NULL, then, there is only one entrybox or none // text2 and gstrUserText2 may only be NULL at the same time // wahtever stays in gstrUserText is displayed in the input area as a predefined text. // when the ENTER is hit in one of the entryboxes 0 (means the first button) is returned. //The Gstrings are updated only when first button is pressed // return values: 0: User OK 1: User Cancel 2: User Cancel All <0: Error TRACEIT(10,"MyEasyInputWidget_Two start"); if (NULL == title || NULL==text1 /*|| NULL==gstrUserText1*/ ){ TRACEIT(3,"MyEasyInputWidget_Two end, one or more parameters NULL"); return -1; } if (NULL == button0 || NULL==button1 /*|| NULL==gstrUserText1*/ ){ TRACEIT(3,"MyEasyInputWidget_Two end, at lease the first two buttons have to be defined"); return -1; } GtkWidget *dialog, *label1, *label2; GtkWidget *EntryBox1=NULL, *EntryBox2=NULL; GString *gstrbuf1 = g_string_sized_new(10); GString *gstrbuf2 = g_string_sized_new(10); int iText2Valid=0; int iText1Valid=0; //dialog = CreateMyDialog(title, parrent, 2, "ok",GTK_RESPONSE_ACCEPT,"cancel",GTK_RESPONSE_REJECT, FALSE); if (button0 && button1 && button2 && button3){ dialog = gtk_dialog_new_with_buttons(title,parrent,GTK_DIALOG_DESTROY_WITH_PARENT, button0, 0, button1, 1, button2, 2, button3, 3, NULL); } else if (button0 && button1 && button2 && button3==NULL){ dialog = gtk_dialog_new_with_buttons(title,parrent,GTK_DIALOG_DESTROY_WITH_PARENT, button0, 0, button1, 1, button2, 2, NULL); } else if(button0 && button1 && button2==NULL && button3==NULL){ dialog = gtk_dialog_new_with_buttons(title,parrent,GTK_DIALOG_DESTROY_WITH_PARENT, button0, 0, button1, 1, NULL); } else{ dialog = gtk_dialog_new_with_buttons(title,parrent,GTK_DIALOG_DESTROY_WITH_PARENT,"Ok",GTK_RESPONSE_ACCEPT,"Cancel all",2,"Cancel",1,NULL); } gtk_window_set_deletable((GtkWindow *)dialog,FALSE); gtk_window_set_resizable((GtkWindow *)dialog,TRUE); g_signal_connect (dialog,"window-state-event",G_CALLBACK(KeepWindowOnTop),(void *)dialog); label1 = gtk_label_new(text1); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),label1); gtk_misc_set_alignment ( (GtkMisc *)label1, 0.0f, 0.0f); gtk_misc_set_padding ( (GtkMisc *)label1, 4, 0); if (gstrUserText1!=NULL){ EntryBox1 = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(EntryBox1),MAXENTRYBOX); gtk_editable_set_editable(GTK_EDITABLE(EntryBox1),TRUE); g_signal_connect (EntryBox1, "activate",G_CALLBACK(MyEasyInputWidget_EntryBoxActivate),dialog); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),EntryBox1); g_object_set(EntryBox1, "text", gstrUserText1->str, NULL); iText1Valid=1; } if (text2 != NULL && gstrUserText2 != NULL){ label2 = gtk_label_new(text2); gtk_misc_set_alignment ( (GtkMisc *)label2, 0.0f, 0.0f); gtk_misc_set_padding ( (GtkMisc *)label2, 4, 0); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),label2); EntryBox2 = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(EntryBox2),MAXENTRYBOX); gtk_editable_set_editable(GTK_EDITABLE(EntryBox2),TRUE); g_signal_connect (EntryBox2, "activate",G_CALLBACK(MyEasyInputWidget_EntryBoxActivate),dialog); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),EntryBox2); g_object_set(EntryBox2, "text", gstrUserText2->str, NULL); iText2Valid=1; } gtk_widget_show_all(dialog); int ret=gtk_dialog_run(GTK_DIALOG(dialog)); if (ret == 0 || ret == GTK_RESPONSE_ACCEPT){ //hitting enter in one of the entryboxes returns GTK_RESPONSE_ACCEPT if (iText1Valid==1){ g_object_get(EntryBox1, "text", gstrbuf1, NULL); g_string_assign(gstrUserText1,gstrbuf1->str); } if (iText2Valid==1){ g_object_get(EntryBox2, "text", gstrbuf2, NULL); g_string_assign(gstrUserText2,gstrbuf2->str); } gtk_widget_destroy(dialog); TRACEIT(10,"MyEasyInputWidget_Two end 0"); g_string_free(gstrbuf2, TRUE); g_string_free(gstrbuf1, TRUE); return 0; //Do not return GTK_RESPONSE_ACCEPT, but 0, this means the first button }/* else if(ret==2){ g_string_free(gstrbuf2, TRUE); g_string_free(gstrbuf1, TRUE); gtk_widget_destroy(dialog); return ret; }*/ gtk_widget_destroy(dialog); TRACEIT(10,"MyEasyInputWidget_Two end 1"); g_string_free(gstrbuf2, TRUE); g_string_free(gstrbuf1, TRUE); return ret; } void AddMyIconsToWindow(GtkWindow *Window){ TRACEIT(10,"AddMyIconsToWindow start"); GString *gstrbuf = g_string_sized_new(20); GString *gstrbuf2 = g_string_sized_new(20); char *cppSizes[] = {"16x16","48x48","64x64"}; //,"128x128","160x160"}; //Do not forgett to de- or increment for-loop when changing Items in this pointerarray int i=0; //On IceWM: when we add more than 64x64 (or 3 Items) there was no Icon at all getHomeDirectory(gstrbuf); checkPathForLastChar(gstrbuf); g_string_append(gstrbuf,ICONNAMEWITHOUTSIZE); GError *err=NULL; GList *pMyIconList=NULL; GdkPixbuf *pixMainWindowIcon=NULL; for (i=0; i<3; i++){ g_string_assign(gstrbuf2, gstrbuf->str); g_string_append(gstrbuf2, cppSizes[i]); g_string_append(gstrbuf2, ".gif"); pixMainWindowIcon = gdk_pixbuf_new_from_file (gstrbuf2->str, &err); if (err){ TRACEIT(6,"AddMyIconsToWindow error Loading Icon from file:"); TRACEIT(6,gstrbuf2->str); g_error_free(err); err=NULL; } if (pixMainWindowIcon != NULL){ pMyIconList = g_list_append(pMyIconList, (void *)pixMainWindowIcon); } } gtk_window_set_icon_list (Window, pMyIconList); g_list_free(pMyIconList); g_string_free(gstrbuf,TRUE); g_string_free(gstrbuf2,TRUE); TRACEIT(10,"AddMyIconsToWindow end"); } void MyEasyInputWidget_EntryBoxActivate(GtkEntry *entry, gpointer data){ TRACEIT(10,"MyEasyInputWidget_EntryBoxActivate start"); gtk_dialog_response (GTK_DIALOG(data), GTK_RESPONSE_ACCEPT); //This is just when the user hits the enterbutton, then the OKButton is activated //!!!!!!!! Be carefull, this function is called from many functions not only the NewDirectory-thing !!!!! TRACEIT(10,"MyEasyInputWidget_EntryBoxActivate ends"); } /* gboolean AddESCButtonToAMainWidget_SignalHandler(GtkWidget *widget, GdkEventKey *event, GtkWidget *TheWidget){ TRACEIT(10,"AddESCButtonToAMainWidget_SignalHandler start"); guint modifiers; modifiers = gtk_accelerator_get_default_mod_mask (); if ( (event->keyval == GDK_Escape)){ gtk_widget_destroy (TheWidget); TRACEIT(10,"createUserCommand_oneKeyPressedInView ends"); return TRUE; } TRACEIT(10,"AddESCButtonToAMainWidget_SignalHandler end"); return FALSE; } */ /* int AddESCButtonToAMainWidget (GtkWidget *TheWidget){ //in the end, this will call gtk_widget_destroy () to TheWidget ! //this means that TheWidget most propably has to be a toplevel widget TRACEIT(10,"AddESCButtonToAMainWidget start"); if (TheWidget == NULL){ TRACEIT(10,"AddESCButtonToAMainWidget parameter NULL"); return -1; } g_signal_connect (TheWidget,"key-press-event",G_CALLBACK(AddESCButtonToAMainWidget_SignalHandler),TheWidget); TRACEIT(10,"AddESCButtonToAMainWidget end"); return 0; } */ gboolean myWrapOf__g_spawn_command_line_sync (const gchar *command_line, gchar **standard_output, gchar **standard_error, gint *exit_status, GError **error, gboolean ThreadSave){ //when ThreadSave is TRUE, all gtk-functions is gdk_threads_enter/leave surrounded. //if it is FALSE, no gdk_threads_enter/leave functions are called in here //if this function is called from within a signal, ThreadSave should be FALSE, as signals are allready threadsafe //A call to the mentioned functions would cause a deadlock. TRACEIT(10,"myWrapOf__g_spawn_command_line_sync start"); gboolean ret; time_t currentTime=0; GString *gstrBuf=g_string_sized_new(30); unsigned int ID; ID = time(¤tTime); g_string_printf(gstrBuf, "%d: %s: %s",ID, ctime(¤tTime), command_line); cutCharFromGString(gstrBuf, '\n',0); //g_string_append(gstrBuf, "\n\n"); if (ThreadSave){ myWrap_gdk_threads_enter("myWrapOf__g_spawn_command_line_sync 1"); } textbuffer_commandHistory_addText(gstrBuf->str, NULL); if (ThreadSave){ myWrap_gdk_threads_leave("myWrapOf__g_spawn_command_line_sync 1"); } //char cbuf[100]; //getcwd(cbuf,99); //printf("current path: %s, command: %s\n",cbuf, command_line); ret = g_spawn_command_line_sync(command_line,standard_output,standard_error,exit_status,error); if (standard_error != NULL && *standard_error != NULL && strlen(*standard_error) > 1 && (( exit_status != NULL && *exit_status != 0) || exit_status==NULL) ){ g_string_printf(gstrBuf, "%d: %s: ERROR: %s",ID, ctime(¤tTime), *standard_error); cutCharFromGString(gstrBuf, '\n',0); //g_string_append(gstrBuf, "\n\n\n"); if (ThreadSave){ //printf("entering gdk_threads\n"); myWrap_gdk_threads_enter("myWrapOf__g_spawn_command_line_sync 2"); //printf("gdk_threads_entered\n"); } textbuffer_commandHistory_addText(gstrBuf->str, "error"); if (ThreadSave){ //printf("going to leave gdk_threas\n"); myWrap_gdk_threads_leave("myWrapOf__g_spawn_command_line_sync 2"); //printf("myWrap_gdk_threads_leaved\n"); } } g_string_free(gstrBuf, TRUE); TRACEIT(10,"myWrapOf__g_spawn_command_line_sync end"); return ret; } void textbuffer_commandHistory_addText (char *text, char *tag){ TRACEIT(10,"textbuffer_commandHistory_addText start"); //adds text to the end of our g_TextBuffer_CommandHistory, //tag may be NULL, otherwise the text is added to the buffer with the tag-properties (the tag must be a valid name of an allready connected tag) //a valid tag e.g. is "error" //when no tag is defined \n\n will be appended to text //wehn tag is defined \n\n\n will be appended to text if (text == NULL){ TRACEIT(2,"textbuffer_commandHistory_addText end, Parameter NULL"); return; } if (g_TextBuffer_CommandHistory == NULL){ TRACEIT(2,"textbuffer_commandHistory_addText end, buffer null"); return; } GtkTextIter iter; GString *gstrText = g_string_new(text); gtk_text_buffer_get_end_iter (g_TextBuffer_CommandHistory, &iter); if (tag == NULL){ g_string_append(gstrText, "\n\n"); gtk_text_buffer_insert (g_TextBuffer_CommandHistory, &iter, gstrText->str, -1); } else{ g_string_append(gstrText, "\n\n\n"); //the error text will displayed in red, as defined within the tag (here refered by "error" (tagname)), defined in defineGlobals - function gtk_text_buffer_insert_with_tags_by_name (g_TextBuffer_CommandHistory, &iter, gstrText->str, -1, tag, NULL); } g_string_free(gstrText, TRUE); //gtk_text_iter_free (&iter); //do not free it, iter is on the stack! (its here just for info) TRACEIT(10,"textbuffer_commandHistory_addText end"); } void CancelButtonFunctionForIBreak(GtkButton *button, gpointer data){ //used or buttons which only have to change the ibreak variable (used in search for..., and SizeDialog) TRACEIT(10,"CancelButtonFunctionForIBreak start"); int *ibreak = (int *)data; *ibreak = 1; TRACEIT(10,"CancelButtonFunctionForIBreak ends"); } int CheckForEndingInEndingList (const char *ccpEndings, const char *ccpSingleEnding){ //ccpEndings is a string of the form: 'jpg png mp3' as used for listing our endings //ccpSingleEnding is the ending we want to check ccpEndings for. //the endings in ccpEndings can be divided by space //return: 0 = not found // 1 = found // -1= error TRACEIT(10,"CheckForEndingInEndingList start"); char *cpBuf = NULL; char *cpBuf2 = NULL; int iRet = 0; char *cpBufSingleEnding = NULL; cpBufSingleEnding = g_ascii_strdown (ccpSingleEnding, -1); if (cpBufSingleEnding == NULL){ TRACEIT (2, "CheckForEndingInEndingList Error converting SingleEnding to lower"); return -1; } cpBuf = malloc (sizeof (char) * (strlen (ccpEndings) + 1)); if (NULL == cpBuf){ free (cpBufSingleEnding); TRACEIT (2, "CheckForEndingInEndingList Error unable to allocate memory"); return -1; } strcpy (cpBuf, ccpEndings); cpBuf2 = strtok (cpBuf, " "); while (NULL != cpBuf2){ if (0 == strcmp (cpBuf2, cpBufSingleEnding)){ iRet = 1; break; } cpBuf2 = strtok (NULL, " "); } free (cpBufSingleEnding); free (cpBuf); TRACEIT(10,"CheckForEndingInEndingList ends"); return iRet; } gboolean ListWidget_MousePressEventCatcher (GtkWidget *widget, GdkEventButton *event, struct ListWidgetCommunicationStruct *commStru){ TRACEIT(10,"ListWidget_MousePressEventCatcher start"); if (commStru == NULL){ TRACEIT (2, "ListWidget_MousePressEventCatcher PARAMETER NULL"); return FALSE; } if (commStru->iListPaused != 0){ TRACEIT(10,"ListWidget_MousePressEventCatcher ends"); return FALSE; } TRACEIT(10,"ListWidget_MousePressEventCatcher ends"); return TRUE; } /* int VersionCheck_Gtk(){ //int lkd_mj = gtk_major_version; int lkd_min = gtk_minor_version; int lkd_mic = gtk_micro_version; GTK_MAJOR_VERSION,GTK_MINOR_VERSION,GTK_MICRO_VERSION if (lkd_min < 10){ return -100; //Cat'sEyE needs at least version 2.10 //the installed version is too little } if (lkd_min < GTK_MINOR_VERSION){ return -10; //compiled versions are highter than linked (minor) } else if (kd_min = GTK_MINOR_VERSION){ if (lkd_mic < GTK_MICRO_VERSION){ return -1; //compiled versions are highter than linked (micro) } else if (kd_mic = GTK_MICRO_VERSION){ return 0; //compiled and linked versions are equal } else if (kd_mic > GTK_MICRO_VERSION){ return 1; //linked version is newer than compiled version (micro) } } else if (kd_min > GTK_MINOR_VERSION){ return 10; //linked version is newer than compiled version (minor) } } */