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
24
#include <glib/gprintf.h>
25
#include <glib/gi18n.h>
26
#include <gconf/gconf.h>
27
#include <gconf/gconf-client.h>
35
#include "interface.h"
36
#include "callbacks.h"
41
GtkWidget *windowMain;
42
GtkWidget *windowPrefsDialog;
43
GtkWidget *windowPropDialog;
44
GtkWidget *windowPlaylistDialog;
45
GtkWidget *windowStatusBar;
46
GtkWidget *toolbuttonConnect;
47
GtkWidget *treeviewFiles;
49
Device_Struct DeviceMgr;
51
LIBMTP_file_t *deviceFiles;
52
LIBMTP_folder_t *deviceFolders;
53
LIBMTP_track_t *deviceTracks;
54
LIBMTP_playlist_t *devicePlayLists;
55
uint32_t currentFolderID;
57
gchar *applicationpath = NULL;
58
GString *file_icon_png;
59
GString *file_icon16_png;
60
GString *file_about_png;
63
main (int argc, char *argv[])
65
setFilePaths(argc, argv);
68
gtk_init (&argc, &argv);
71
//setlocale(LC_ALL, ""); // This is done in gtk_set_locale();
72
bindtextdomain (PACKAGE, g_strconcat(applicationpath, "/../share/locale", NULL));
73
//bindtextdomain (PACKAGE, "/usr/local/share/locale");
74
bind_textdomain_codeset (PACKAGE, "UTF-8");
80
windowMain = create_windowMain ();
81
gtk_widget_show (windowMain);
83
//Set default state for application
84
DeviceMgr.deviceConnected = FALSE;
85
statusBarSet(_("No device attached"));
86
SetToolbarButtonState(DeviceMgr.deviceConnected);
90
// If preference is to auto-connect then attempt to do so.
91
if(Preferences.attemptDeviceConnectOnStart == TRUE)
92
on_deviceConnect_activate(NULL, NULL);
94
// If we do have a connected device, then do a rescan operation to fill in the filelist.
95
if(DeviceMgr.deviceConnected == TRUE)
102
void setFilePaths(int argc, char *argv[]){
103
applicationpath = getRuntimePath(argc, argv);
104
file_icon_png = g_string_new(applicationpath);
105
file_icon_png = g_string_append(file_icon_png, "/../share/gmtp/icon.png");
106
file_icon16_png = g_string_new(applicationpath);
107
file_icon16_png = g_string_append(file_icon16_png, "/../share/gmtp/icon-16.png");
108
file_about_png = g_string_new(applicationpath);
109
file_about_png = g_string_append(file_about_png, "/../share/gmtp/stock-about-16.png");
112
gchar *getRuntimePath(int argc, char *argv[]){
116
gchar *foundpath = NULL;
117
const char delimit[]=";:";
121
/*g_printf("Arguments:\n");
122
for (i = 0; i < argc; i++) {
123
g_printf("%i: %s\n", i, argv[i]);
125
if(g_ascii_strcasecmp(PACKAGE, argv[0]) == 0){
126
//g_printf("Executed from %%PATH\n");
127
//g_printf("%%PATH = %s\n", getenv("PATH"));
128
// list each directory individually.
129
fullpath = g_strdup(getenv("PATH"));
130
token = strtok (fullpath, delimit);
131
while((token != NULL)&&(foundpath == NULL)){
132
//g_printf("Path = %s\n", token);
133
// Now test to see if we have it here...
134
filepath = g_strdup(token);
135
filepath = g_strconcat(filepath, "/", PACKAGE, NULL);
136
//g_printf("Testing %s\n", filepath);
137
if(access(filepath, F_OK) != -1){
138
// g_printf("Found the file: %s\n", filepath);
139
foundpath = g_strdup(token);
141
token = strtok(NULL, delimit);
145
foundpath = g_strdup(dirname(argv[0]));
148
// We have some other options, lets check for --datapath
149
if(g_ascii_strcasecmp("--datapath", argv[1]) == 0){
150
// our first argument is --datapath, so set the path to argv[2];
151
foundpath = g_strdup(argv[2]);
154
//if(foundpath != NULL)
155
//g_printf("Executed from %s\n", foundpath );