1 /*
2     Copyright 2007, 2008, 2009, 2010 Geyer Klaus
3 
4     This file is part of Cat'sEyE.
5 
6     Cat'sEyE is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10 
11     Cat'sEyE is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with Cat'sEyE.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef LISTS_H_
21 #define LISTS_H_
22 
23 
24 /////////////////////////////////////////////////////////////////////////////////////////////////
25 ///////////////// UPDATE LIST /////////////////////////////////////////////////////////////////
26 /////////////////////////////////////////////////////////////////////////////////////////////////
27 // Be carefull changing this, because this list is also used in other terms (e.g. when marking all items which are of the same type as the already marked one ( markItemsWithSameType )
28 struct updateList{
29     GString *gstrName;
30     GString *gstrPath;
31     GtkTreeRowReference  *rowref;
32     int found;
33 
34     struct updateList *PrevItem;
35     struct updateList *NextItem;
36 };
37 
38 void updateList_addItem(struct updateList **itemlist, char *Name, char *Path, GtkTreeRowReference *rowref, int found);
39 void updateList_deleteList(struct updateList **itemlist);
40 void updateList_getFirstItem(struct updateList **itemlist);
41 GtkTreeRowReference *updateList_checkForItem(struct updateList **itemlist, char *Name);
42 int updateList_checkForItem_NoRef(struct updateList **itemlist, char *Name);
43 
44 
45 /////////////////////////////////////////////////////////////////////////////////////////////////
46 ///////////////// SIDE OBJECT LIST //////////////////////////////////////////////////////////////
47 /////////////////////////////////////////////////////////////////////////////////////////////////
48 
49 struct SideObjectList{
50 
51 	GtkNotebook 		*notebook;
52 	GtkWidget 			*listView;
53 	GtkListStore		*listStore;
54 	GtkWidget			*ScrollWindow;
55 	GString 			*gstrPath;
56 	gboolean			showHiddenFiles;
57 	gboolean 			alwaysShowHiddenFiles;	//set from a global variable, tunabel by the user via the internal menu. overwrites (but not echange) the value of showHiddenFiles in case it is true.
58 	GtkTreeViewColumn	*actualSortCol;
59 	GtkTreeViewColumn   *PreviewCol;
60 	GtkVBox 			*VBox; 			//Holds scrollview, and StatusBar
61 	GtkStatusbar		*StatusBar;
62 	guint64				guint64sizeOfSelectedItems;
63 	GtkWidget			*label;
64 	int                 iRecursiveSizeCalculation;  //-1 if there is not such a calculation, 0 if the size of the directories viewed are currently calculated
65                                                     //with 'F6' threads are created which calculate the size of each directory shown on the view. The sizes
66                                                     //are also shown within the view as sizes of the items. When this Object gets a normal update (e.g. by changing the directory)
67                                                     //this variable becomes -1 again and all threads stop calculating immediately.
68 
69     int                 iPreview;                   //Pictures can be previewed if the user wants it. 0 -> Preview disabled, !=0 -> Preview enabled
70 
71     //Update Flags:
72     int                 iPreventFromUpdating;        //1=do not update this Object (view), 0:Update this Object when nessecary
73                                                     //added because of our new automatic update, in case we rename items we have to
74                                                     //prevent updating. Who ever sets this flag, has to delete it!
75     gboolean            bUpdateFlag_UpdateOnTabSwitch;      // *1
76     gboolean            bUpdateFlag_F6;                     // *2
77     gboolean            bUpdateFlag_CurrentlyUpdating;      // *3
78     gboolean            bUpdateFlag_UserWantsToUpdate;      // *4
79     GThread             *gthreadF6Updage;
80 
81     gboolean            bPointsAddedToView;          //a flag inticating that the points (. ..) were added to the current view (makeLists)
82 	gboolean			bReadOnly;	//the user can mark a tab as read only, copying to, moving from or to or deleting in this tab is prohibited
83 
84 
85 	gpointer			data;			//UserData some Functions need, e.g. the copyToOtherPannel
86 
87 	struct SideObjectList 		*NextItem;
88 	struct SideObjectList 		*PrevItem;
89 };
90 
91 //  *1:     if there is a monitor callback, and the tab viewing the folder monitored is not active, this flag becomes TRUE
92 //          When the Tab becomes active this flag is checked whether we need to update the tabObject (TRUE) or not (FALSE).
93 //          gets false after update.
94 //  *2:     becomes TRUE if the user pressed F6 in the view and prevents object from beeing updated
95 //          changing tab or updating with F5 deletes this flag. This flag is used to interrupt the size calculation thread
96 //  *3:     The name says it all, while we Update the view wth updateViewWithNewFolder, this flag is TRUE, when it is finished it is FALSE
97 //  *4:     If the user explicitly updates with F5 or changes the Folder this update has highest priority, autoatic updates are ignored
98 
99 int SideObjectList_StartWithObjectList(GtkNotebook *notebook, char *Path);
100 void SideObjectList_ProcessNewItem(GtkNotebook *notebook, struct SideObjectList *Object, char *Path, struct SideObjectList *OldObject);
101 int SideObjectList_CreateNewViewWithPath(GtkNotebook *notebook, char *Path, struct SideObjectList *OldObject);
102 int SideObjectList_GetActiveObject(GtkNotebook *notebook, struct SideObjectList **Object);
103 int SideObjectList_GetObjectByPageNumber(GtkNotebook *notebook, struct SideObjectList **Object, guint Number);
104 int SideObjectList_GetObjectByChildListView(struct SideObjectList **Object, GtkTreeView *listView, int *side);
105 int SideObjectList_GetObjectByChildVBox(struct SideObjectList **Object, GtkWidget *vbox, int *side);
106 void SideObjectList_UpdateObject(struct SideObjectList *Object);
107 void SideObjectList_DeleteActiveObject(GtkNotebook *notebook);
108 void SideObjectList_ClearObject(struct SideObjectList *Object);
109 void SideObjectList_MoveActiveObject(GtkNotebook *srcnotebook, GtkNotebook *destnotebook);
110 int SideObjectList_ValidateObject(struct SideObjectList *Object);
111 struct SideObjectList *SideObjectList_getFirstObject();
112 struct SideObjectList *SideObjectList_getNextObejct(struct  SideObjectList *Object);
113 void SideObjectList_ClearAllForShutdown();
114 void SideObjectList_UnrefPreviewPixbufs(GtkListStore *listStore, int iColumn);
115 
116 
117 /////////////////////////////////////////////////////////////////////////////////////////////////
118 ///////////////// FILESHELF OBJECT LIST /////////////////////////////////////////////////////////
119 /////////////////////////////////////////////////////////////////////////////////////////////////
120 
121 
122 struct FileShelfObjectList{
123 	GtkNotebook		    *notebook;		//This never changes for the fileshelf Object, I dont know if I gonna use this
124 	GtkWidget		    *listView;
125 	GtkListStore		*listStore;
126 	GtkWidget		    *ScrollWindow;
127 	GtkTreeViewColumn 	*actualSortCol;
128 	GtkTreeViewColumn   *PreviewCol;
129 	GtkWidget		    *label;
130     int                 iRecursiveSizeCalculation;  //-1 if there is not such calculation, 0 if the size of the directories viewed are currently calculated
131                                                     //with 'F6' threads are created which calculate the size of each directory shown on the view. The sizes
132                                                     //are also shown within the view as sizes of the items. When this Object gets a normal update (e.g. by changing the directory)
133                                                     //this variable becomes -1 again and all threads stop calculating emetiadly.
134 
135     int                 iPreview;                   //Pictures can be previewed if the user wants it. 0 -> Preview disabled, !=0 -> Preview enabled
136 
137 	gpointer		    data;			//UserData some Functions need (e.g. copyFileShelfToPannel)
138 	int				    iCopyReMoveSide;	//Holds information to which side the items of the Fileshelf should be CopyReMoved
139 	int					ID;				//unique ID of this FileShelf, Randomnumber
140 
141     GThread             *gthreadF6Updage;
142 
143 	struct FileShelfObjectList *NextItem;
144 	struct FileShelfObjectList *PrevItem;
145 };
146 
147 struct FileShelfObjectList *FileShelftObjectList_getFirstObject();
148 struct FileShelfObjectList *FileShelfObjectList_getNextObejct(struct  FileShelfObjectList *Object);
149 int 						FileShelfObjectList_StartWithObjectList();
150 void 						FileShelfObjectList_ClearAllForShutdown();
151 void 						FileShelfObjectList_GetActiveObject(struct FileShelfObjectList **Object);
152 int 						FileShelfObjectList_ValidatObject(struct FileShelfObjectList *Object);
153 int 						FileShelfObjectList_NewObject(struct FileShelfObjectList **RetObject);
154 void 						FileShelfObjectList_DeleteObject(struct FileShelfObjectList *Object);
155 
156 int                         FileShelfObjectList_GetObjectByChildListView(struct FileShelfObjectList **Object, GtkTreeView *listView);
157 int                         FileShelfObjectList_GetObjectByPageNumber(struct FileShelfObjectList **Object, guint Number);
158 struct FileShelfObjectList *FileShelfObjectList_GetObjectByID(const int ID);
159 int                         FileShelfObjectList_GetPageNumberByID(struct FileShelfObjectList *Object, int ID);
160 int                         FileShelfObjectList_GetPageNumberByObject(struct FileShelfObjectList *Object);
161 int                         FileShelfObjectList_GetIDByPageNumber(int iPageNumber);
162 
163 
164 
165 /////////////////////////////////////////////////////////////////////////////////////////////////
166 ///////////////// CopyReMove LISTS //////////////////////////////////////////////////////////////
167 /////////////////////////////////////////////////////////////////////////////////////////////////
168 
169 struct CopyReMoveList{
170 	GString                 *string1;
171 	GString                 *string2;
172 	struct SideObjectList   *SrcObject;
173 	struct SideObjectList   *DestObject;
174 	struct FileShelfObjectList *FileShelfObject;
175 
176 
177 	int             status;	//-10 means cancel, 1: Item Processed, 0:Item in process, -1:Item not processed yet,
178 	GtkTreeIter     iter; //used for storing iter for ListView
179 	int             CopyMoveOrRemove; //1=copy, 2=move, 3=remove
180 
181 	GString         *UserCommand; //to store the usercommand that will be used with the list
182 	GString         *gstrCaption;		//Used with the usercommand to view the right strings in the list widget (call via list)
183 	GString         *gstrLabel;			//Used with the usercommand to view the right strings in the list widget (call via list)
184 
185 	GString         *Errors;    //Errors and outpuT from the system-command
186 
187 
188     ///// New copy methode:
189     //GError *error;
190     guint64         iBytesToCopy;
191     gint64          iBytesCopied;
192     int             iBytesToCopyIsValid;    //because the bytes to copy are checked recursive, we have to check wheter it is ready or not.
193                                 //0=invalid, 1=valid
194 
195     guint64         *ui64pTotalBytesCopied; //a pointer to ListWidgetCommunicationStructs ui64TotalBytesProcessed
196     gint64          *i64pStartTotalBytesCopied;
197     GTimeVal        *timepStartTimeForBytesCopied;
198     GTimeVal        *timepStartTimeForBytesCopiedSingleItem;
199     guint64         *ui64TotalBytes;         // a pointer to ListWidgetCommunicationStruct's ui64TotalBytes
200     int             *iTotalBytesValid;       // a pointer to ListWidgetCommunicationStructs iTotalBytesValid
201     double          *dpCopySpeed;
202     GtkProgressBar  *progressBar;    //pointer to ListWidgetCommunicationStruct's progressBar
203     GString         *ErrorMessage; //Error while recursive procedure;
204     int             ibreak; // 1 == break, 0=continue. used mainly for calculating size
205     gboolean        bOverWriteExisting; //True: user said yes
206     //GThread *threadCalcSizeAfterProcessing;     //holds the thread wich is start after copyReMoveRecursive ends. and calcs the size of
207                                                 //of the destination and compairs it with the source size, allready calculated
208     GtkListStore    *listStore;        //a pointer to the list store, used in the thread CalcSizeAfterCopyMove, which calcs the size of
209                                     //the destination to check it.
210     goffset         lastfinishedTotalBytes; //used in copyItemRecursive_Callback (used to calc the size of processed items)
211     GThread         *threadCalcSize;        //the thread which calcs the size for one item
212 
213 	struct CopyReMoveList *NextItem;
214 	struct CopyReMoveList *PrevItem;
215 };
216 int CopyReMoveList_AddItem(struct CopyReMoveList **FirstItem, char *string1, char *string2, struct SideObjectList *SrcObject, struct SideObjectList *DestObject, struct FileShelfObjectList *FileShelfObject);
217 int CopyReMoveList_DeleteList(struct CopyReMoveList *FirstItem);
218 int CopyReMoveList_CopyList (struct CopyReMoveList **NewList, struct CopyReMoveList *OldList);
219 int CopyReMoveList_initializeMemberTo (struct CopyReMoveList *Item, GtkListStore *listStore, GtkTreeIter iter, guint64 *ui64pTotalBytesCopied, gint64 *i64pStartTotalBytesCopied, GTimeVal *timepStartTimeForBytesCopied, GTimeVal *timepStartTimeForBytesCopiedSingleItem, guint64 *ui64TotalBytes, int *iTotalBytesValid, GtkProgressBar *progressBar, int CopyMoveOrRemove, double *dpCopySpeed );
220 int CopyReMoveList_ConnectTwoLists (struct CopyReMoveList *FirstList, struct CopyReMoveList *SecondList );
221 struct CopyReMoveList *CopyReMoveList_removeItemFromList (struct CopyReMoveList *theItem);
222 int CopyReMoveLis_deleteItemMember (struct CopyReMoveList *FirstItem);
223 
224 /////////////////////////////////////////////////////////////////////////////////////////////////
225 ///////////////// COMMUNICATION STRUCT //////////////////////////////////////////////////////////////
226 /////////////////////////////////////////////////////////////////////////////////////////////////
227 //for communication between copyReMove threads
228 
229 struct ListWidgetCommunicationStruct {  //used for communication between the signals in the procedure handling processing items via list
230     GtkWidget       *mainListWidget;
231     GtkWidget       *listView;
232     GtkWidget       *TheLabel;
233     GtkListStore    *listStore; //needs an unrefere call
234     GtkButton       *cancelButton;
235     GtkButton       *closeButton;
236     GtkButton       *pauseButton;
237     GtkButton       *continueButton;
238     #ifndef NO_GIO
239     GCancellable    *cancellable;
240     #else
241     void            *cancellable;
242     #endif
243     GString         *WindowName;
244     GError *        gerror;
245 
246     int         SecondThreadRunning;    //set to 0 in 1st thread, 1 as long as 2nd thread runs
247     GThread     *gthrdCopyReMoveThread_1; //for joining the copyRemove Thread, processing the currentItem (member of this struct)
248     GThread     *gthrdCopyReMoveThread_2;
249     GMutex      *mtxContinue;   //mutex for the pause-continue procedure over several threads
250     int         iNextThreadStarted; //helps with the mtxContinue
251    // int iNotify; //used to decide if we come from the closebutton or from the X in the right upper corner
252     int         iSomeError; //becomes != 0 if there was an error while processing the list;
253     int         iCancelled; //because canceling is processed over threads it may not be that fast as we need it. Therefore this becomes 1 if the list was cancelled
254     int         iListPaused; //becomes 1 if the list is paused, otherwise its 0
255     int         iListPausedAutomatic; //becomes one if the the list is paused because of the drag-motion signal
256     int         iCancelDialogRuns;  //this becomes 1 if the cancel Dialog runs, other wise its 0
257     int         iDestroyFlag;       //1 if the all is done and the next function stumble over this can free all
258     gboolean (*FreeMemoryAndDeleteWidgetFunction)();  //the function to frees the memory, and destroys the widget
259     void (*CancelListFunction)();   //the function used to cancel the list (listbuf->status=0,g_cancellable_cancel)
260     guint64     ui64TotalBytes;         //total bytes of all items in the list going to copied/moved
261     guint64     ui64TotalBytesProcessed;//bytes copied (from total);
262     gint64      i64StartTotalBytesCopied;
263     GTimeVal    timeStartTimeForBytesCopied;
264     GTimeVal    timeStartTimeForBytesCopiedSingleItem;
265     double      dCopySpeed;
266     int         iTotalBytesValid;           //0=not valid, still in process. 1=valid
267     GtkProgressBar *progressBar;    //the progressbar for total amount of copied bytes
268     GtkTreeIter *iterLastProcessedItem; //when pausing the list, this becomes the iter of the item which was processed at this time. so we can restore the markings
269 
270     int         bOverWriteAllExisting;      //-1:not asked, 1=user said yes to all, 0=user said no to all
271 
272     struct _CallUserCommand_StartThreadStructure *ThreadStartStruct;    //for our UserCommandViaList
273 
274     struct CopyReMoveList *firstItem;
275     struct CopyReMoveList *currentItem;
276 
277 
278 };
279 
280 
281 #endif //LISTS_H_
282 
283 
284