Added "--with-userdir" to configure script to change the default user settings directory
[synfig.git] / synfig-studio / trunk / src / gtkmm / app.cpp
index 7295b3e..14c962e 100644 (file)
@@ -5,16 +5,17 @@
 **     $Id: app.cpp,v 1.11 2005/03/24 21:47:28 darco Exp $
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package 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 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package 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.
 **     \endlegal
 */
 /* ========================================================================= */
@@ -31,6 +32,9 @@
 #include <fstream>
 #include <iostream>
 
+#ifdef HAVE_SYS_ERRNO_H
+#include <sys/errno.h>
+#endif
 #include <gtkmm/fileselection.h>
 #include <gtkmm/dialog.h>
 #include <gtkmm/label.h>
 #endif
 
 #ifdef WIN32
+#define _WIN32_WINNT 0x0500
 #include <windows.h>
 #endif
 #include <gtkmm/accelmap.h>
+#include <gtkmm/filechooser.h>
+#include <gtkmm/filechooserdialog.h>
 
 #endif
 
@@ -124,6 +131,14 @@ using namespace studio;
 
 /* === M A C R O S ========================================================= */
 
+#ifndef SYNFIG_USER_APP_DIR
+#ifdef __APPLE__
+#define SYNFIG_USER_APP_DIR    "Library/Synfig"
+#else
+#define SYNFIG_USER_APP_DIR    "Synfig"
+#endif
+#endif
+
 #ifndef DPM2DPI
 #define DPM2DPI(x)     (float(x)/39.3700787402f)
 #define DPI2DPM(x)     (float(x)*39.3700787402f)
@@ -450,6 +465,7 @@ int v_key_check(const char* key, U32* serial, U32 appid)
 
 int check_license(String basedir)
 {
+#ifdef LICENSE_KEY_REQUIRED
        String key;
        String license_file;
 
@@ -488,6 +504,9 @@ int check_license(String basedir)
        }
        synfig::info("License Authenticated -- Serial #%05d",serial);
        return serial;
+#else
+       return 1;
+#endif 
 }
 
 /*
@@ -650,7 +669,7 @@ public:
        }
 };
 
-static Preferences _preferences;
+static ::Preferences _preferences;
 
 void
 init_ui_manager()
@@ -1329,11 +1348,7 @@ App::~App()
 String
 App::get_user_app_directory()
 {
-#ifdef __APPLE__
-       return Glib::build_filename(Glib::get_home_dir(),"Library/Synfig");
-#else
-       return Glib::build_filename(Glib::get_home_dir(),"Synfig");
-#endif
+       return Glib::build_filename(Glib::get_home_dir(),SYNFIG_USER_APP_DIR);
 }
 
 synfig::String
@@ -1645,6 +1660,21 @@ App::dialog_open_file(const std::string &title, std::string &filename)
        if(!_preferences.get_value("curr_path",prev_path))
                prev_path=".";
        
+    Gtk::FileChooserDialog *dialog=new Gtk::FileChooserDialog(title,Gtk::FILE_CHOOSER_ACTION_OPEN);
+    dialog->set_current_folder(prev_path);
+    dialog->add_button(Gtk::StockID("gtk-ok"),GTK_RESPONSE_ACCEPT);
+    dialog->add_button(Gtk::StockID("gtk-cancel"),GTK_RESPONSE_CANCEL);
+    if(!filename.empty())
+        dialog->set_filename(filename);
+    if(dialog->run()==GTK_RESPONSE_ACCEPT) {
+        filename=dialog->get_filename();
+        delete dialog;
+        return true;
+    }
+    delete dialog;
+    return false;
+    /*
+    
        GtkWidget *ok;
        GtkWidget *cancel;
        int val=0;
@@ -1686,6 +1716,7 @@ App::dialog_open_file(const std::string &title, std::string &filename)
        }
        gtk_widget_destroy(fileselection);
        return true;
+    */
 #endif
 }
 
@@ -1734,7 +1765,24 @@ App::dialog_save_file(const std::string &title, std::string &filename)
        }
        return false;
 #else
-       return dialog_open_file(title, filename);
+       synfig::String prev_path;
+       if(!_preferences.get_value("curr_path",prev_path))
+               prev_path=".";
+       
+    Gtk::FileChooserDialog *dialog=new Gtk::FileChooserDialog(title,Gtk::FILE_CHOOSER_ACTION_SAVE);
+    dialog->set_current_folder(prev_path);
+    dialog->add_button(Gtk::StockID("gtk-ok"),GTK_RESPONSE_ACCEPT);
+    dialog->add_button(Gtk::StockID("gtk-cancel"),GTK_RESPONSE_CANCEL);
+    if(!filename.empty())
+        dialog->set_filename(filename);
+    if(dialog->run()==GTK_RESPONSE_ACCEPT) {
+        filename=dialog->get_filename();
+        delete dialog;
+        return true;
+    }
+    delete dialog;
+    return false;
+//     return dialog_open_file(title, filename);
 #endif
 }
 
@@ -1783,7 +1831,24 @@ App::dialog_saveas_file(const std::string &title, std::string &filename)
        }
        return false;
 #else
-       return dialog_open_file(title, filename);
+       synfig::String prev_path;
+       if(!_preferences.get_value("curr_path",prev_path))
+               prev_path=".";
+       
+    Gtk::FileChooserDialog *dialog=new Gtk::FileChooserDialog(title,Gtk::FILE_CHOOSER_ACTION_SAVE);
+    dialog->set_current_folder(prev_path);
+    dialog->add_button(Gtk::StockID("gtk-ok"),GTK_RESPONSE_ACCEPT);
+    dialog->add_button(Gtk::StockID("gtk-cancel"),GTK_RESPONSE_CANCEL);
+    if(!filename.empty())
+        dialog->set_filename(filename);
+    if(dialog->run()==GTK_RESPONSE_ACCEPT) {
+        filename=dialog->get_filename();
+        delete dialog;
+        return true;
+    }
+    delete dialog;
+    return false;
+//     return dialog_open_file(title, filename);
 #endif
 }
 
@@ -1919,6 +1984,12 @@ App::open(std::string filename)
 bool
 App::open_as(std::string filename,std::string as)
 {
+#ifdef WIN32
+    char long_name[1024];
+    if(GetLongPathName(as.c_str(),long_name,sizeof(long_name)));
+    as=long_name;
+#endif
+
        try
        {
                OneMoment one_moment;