5
* Copyright (C) 2009-2011 Darran Kartaschew
7
* This file is part of the gMTP package.
9
* gMTP is free software; you can redistribute it and/or modify
10
* it under the terms of the BSD License as included within the
11
* file 'COPYING' located in the root directory
15
This file contains all the Drag and Drop Functionality for gMTP
22
#include <glib/gprintf.h>
23
#include <glib/gi18n.h>
24
#include <gconf/gconf.h>
25
#include <gconf/gconf-client.h>
26
#include <sys/types.h>
33
#include "interface.h"
34
#include "callbacks.h"
39
const GtkTargetEntry _gmtp_drop_types[] =
41
{"text/plain", 0, GMTP_DROP_PLAINTEXT},
42
{"text/uri-list", 0, GMTP_DROP_URLENCODED},
43
{"STRING", 0, GMTP_DROP_STRING}
46
void gmtp_drag_data_received(GtkWidget * widget,
47
GdkDragContext * context,
50
GtkSelectionData * selection_data,
55
if (selection_data->data)
59
//g_printf("Selection->data = %s\n", selection_data->data);
61
files = getFilesListURI((gchar *)selection_data->data);
63
//g_print("Do each file\n");
64
g_slist_foreach(files, (GFunc)__filesAdd, NULL);
66
// Now clear the GList;
67
g_slist_foreach(files, (GFunc)g_free, NULL);
69
// Now do a device rescan to see the new files.
71
deviceoverwriteop = MTP_ASK;
75
GSList* getFilesListURI(gchar* rawdata){
76
// The data is just the data in string form
77
// Files are in the URI form of file:///filename\n so just look for those,
78
// and if found see if a folder or not?
79
// Then create a slist of those and use filesAdd() to add them in .
85
//struct stat statbuf;
86
const char delimit[]="\n\r";
90
fullpath = g_strdup(rawdata);
92
token = strtok (fullpath, delimit);
93
while((token != NULL)){
94
// Now test to see if we have it here...
95
filepath = g_strdup(token);
96
// See if we have a local file URI, otherwise discard.
97
if(!g_ascii_strncasecmp(filepath, "file://", 7)){
98
tmpstring = g_filename_from_uri(filepath, NULL, NULL);
99
if (g_file_test(tmpstring, G_FILE_TEST_IS_REGULAR ) == TRUE){
100
filelist = g_slist_append(filelist, g_strdup(tmpstring));
102
//g_printf("Parsing folder \"%s\" via DnD interface\n", tmpstring);
103
addFilesinFolder(tmpstring);
107
token = strtok(NULL, delimit);
114
void addFilesinFolder(gchar* foldername){
115
// foldername is the name of the folder as the absolute path with leading /
116
// We save the currentFolderID, create a new folder on the device,
117
// and set currentFolderID to the new folders ID.
118
// Then scan the folder (on the filesystem) adding in files as needed.
119
// Found folders are always added first, so files are copied from
120
// the deepest level of the folder hierarchy first as well, and we
121
// work our way back down towards to the initial folder that was
123
// Lastly we restore the currentFolderID back to what it was.
126
const gchar *filename;
127
gchar* relative_foldername;
129
uint32_t oldFolderID;
132
// Save our current working folder.
133
oldFolderID = currentFolderID;
134
// Get just the folder name, as we are given a full absolute path.
135
relative_foldername = basename(foldername);
136
if(relative_foldername != NULL){
137
//g_printf("New MTP Folder = %s\n", relative_foldername);
138
// Add our folder to the mtp device and set our new current working folder ID.
139
currentFolderID = folderAdd(relative_foldername);
142
// Start scanning the folder on the filesystem for our new files/folders.
143
fileImageDir = g_dir_open(foldername, 0, NULL);
144
// Now parse that directory looking for JPEG/PNG files (based on settings).
145
// If we find one, we create a new GString and add it to the list.
146
if(fileImageDir != NULL){
147
filename = g_dir_read_name(fileImageDir);
148
while(filename != NULL){
149
// See if a file or a folder?
150
tmpstring = g_strconcat(foldername, "/", filename, NULL);
151
if (g_file_test(tmpstring, G_FILE_TEST_IS_REGULAR ) == TRUE){
152
// We have a regular file. So add it to the list.
153
//g_printf("File = %s\n", tmpstring);
154
filelist = g_slist_append(filelist, g_strdup(tmpstring));
156
if (g_file_test(tmpstring, G_FILE_TEST_IS_DIR ) == TRUE){
157
// We have another folder so recursively call ourselves...
158
//g_printf("Folder = %s\n", tmpstring);
159
addFilesinFolder( tmpstring);
162
filename = g_dir_read_name(fileImageDir);
166
// Upload our given files in the current selected folder.
167
if(filelist != NULL){
168
//g_print("Do each file\n");
169
g_slist_foreach(filelist, (GFunc)__filesAdd, NULL);
171
// Now clear the GList;
172
g_slist_foreach(filelist, (GFunc)g_free, NULL);
173
g_slist_free(filelist);
175
if(fileImageDir != NULL)
176
g_dir_close(fileImageDir);
177
// Restore our current working folder.
178
currentFolderID = oldFolderID;