~ubuntu-branches/debian/sid/gmtp/sid

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-01-24 17:21:38 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110124172138-30ssabr3ki093ji8
Tags: 0.8-1
* New upstream release.
* Refresh patches.
* Update debian/copyright.
* Add patch to improve the Italian translation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
*
 
3
*   File: main.c
 
4
*   
 
5
*   Copyright (C) 2009-2011 Darran Kartaschew
 
6
*
 
7
*   This file is part of the gMTP package.
 
8
*
 
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
 
12
*
 
13
*/
 
14
 
 
15
#include "config.h"
 
16
 
 
17
#include <stdlib.h>
 
18
#include <stdio.h>
 
19
#include <libintl.h>
 
20
#include <locale.h>
 
21
 
 
22
#include <glib.h>
 
23
#include <gtk/gtk.h>
 
24
#include <glib/gprintf.h>
 
25
#include <glib/gi18n.h>
 
26
#include <gconf/gconf.h>
 
27
#include <gconf/gconf-client.h>
 
28
#include <libmtp.h>
 
29
#include <libgen.h>
 
30
#include <unistd.h>
 
31
#include <string.h>
 
32
#include <id3tag.h>
 
33
 
 
34
#include "main.h"
 
35
#include "interface.h"
 
36
#include "callbacks.h"
 
37
#include "mtp.h"
 
38
#include "prefs.h"
 
39
#include "dnd.h"
 
40
 
 
41
GtkWidget *windowMain;
 
42
GtkWidget *windowPrefsDialog;
 
43
GtkWidget *windowPropDialog;
 
44
GtkWidget *windowPlaylistDialog;
 
45
GtkWidget *windowStatusBar;
 
46
GtkWidget *toolbuttonConnect;
 
47
GtkWidget *treeviewFiles;
 
48
 
 
49
Device_Struct DeviceMgr;
 
50
 
 
51
LIBMTP_file_t   *deviceFiles;
 
52
LIBMTP_folder_t *deviceFolders;
 
53
LIBMTP_track_t *deviceTracks;
 
54
LIBMTP_playlist_t *devicePlayLists;
 
55
uint32_t currentFolderID;
 
56
 
 
57
gchar *applicationpath = NULL;
 
58
GString *file_icon_png;
 
59
GString *file_icon16_png;
 
60
GString *file_about_png;
 
61
 
 
62
int
 
63
main (int argc, char *argv[])
 
64
{
 
65
    setFilePaths(argc, argv);
 
66
 
 
67
    gtk_set_locale ();
 
68
        gtk_init (&argc, &argv);
 
69
 
 
70
    #ifdef ENABLE_NLS
 
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");
 
75
        textdomain (PACKAGE);
 
76
    #endif
 
77
 
 
78
        LIBMTP_Init();
 
79
 
 
80
        windowMain = create_windowMain ();
 
81
        gtk_widget_show (windowMain);
 
82
 
 
83
        //Set default state for application
 
84
        DeviceMgr.deviceConnected = FALSE;
 
85
        statusBarSet(_("No device attached"));
 
86
        SetToolbarButtonState(DeviceMgr.deviceConnected);
 
87
 
 
88
    setupPreferences();
 
89
 
 
90
        // If preference is to auto-connect then attempt to do so.
 
91
        if(Preferences.attemptDeviceConnectOnStart == TRUE)
 
92
                on_deviceConnect_activate(NULL, NULL);
 
93
 
 
94
        // If we do have a connected device, then do a rescan operation to fill in the filelist.
 
95
        if(DeviceMgr.deviceConnected == TRUE)
 
96
                deviceRescan();
 
97
 
 
98
        gtk_main ();
 
99
        return 0;
 
100
}
 
101
 
 
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");
 
110
}
 
111
 
 
112
gchar *getRuntimePath(int argc, char *argv[]){
 
113
    //gint i;
 
114
    gchar *fullpath;
 
115
    gchar *filepath;
 
116
    gchar *foundpath = NULL;
 
117
    const char delimit[]=";:";
 
118
    gchar *token;
 
119
    
 
120
    // Prints arguments
 
121
    /*g_printf("Arguments:\n");
 
122
    for (i = 0; i < argc; i++) {
 
123
        g_printf("%i: %s\n", i, argv[i]);
 
124
    }*/
 
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);
 
140
            }
 
141
            token = strtok(NULL, delimit);
 
142
            g_free(filepath);
 
143
        }
 
144
    } else {
 
145
        foundpath = g_strdup(dirname(argv[0]));
 
146
    }
 
147
    if(argc == 3){
 
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]);
 
152
        }
 
153
    }
 
154
    //if(foundpath != NULL)
 
155
        //g_printf("Executed from %s\n", foundpath );
 
156
    return foundpath;
 
157
}