]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/main.cpp
Remove <gtk/gtk.h> from most of radiant/*
[xonotic/netradiant.git] / radiant / main.cpp
index 196297ede2ad6e226e14ade58e077afc2585bc31..ea9bdc695a13afeabd1aea3c61cc3723c2eb1cca 100644 (file)
@@ -69,7 +69,7 @@
 
 #include "iundo.h"
 
-#include <gtk/gtkmain.h>
+#include "uilib/uilib.h"
 
 #include "cmdlib.h"
 #include "os/file.h"
@@ -303,12 +303,12 @@ bool handleMessage(){
                ScopedLock lock( m_lock );
 #if defined _DEBUG
                m_buffer << "Break into the debugger?\n";
-               bool handled = gtk_MessageBox( 0, m_buffer.c_str(), "Radiant - Runtime Error", eMB_YESNO, eMB_ICONERROR ) == eIDNO;
+               bool handled = ui::root.alert( m_buffer.c_str(), "Radiant - Runtime Error", ui::alert_type::YESNO, ui::alert_icon::Error ) == ui::alert_response::NO;
                m_buffer.clear();
                return handled;
 #else
                m_buffer << "Please report this error to the developers\n";
-               gtk_MessageBox( 0, m_buffer.c_str(), "Radiant - Runtime Error", eMB_OK, eMB_ICONERROR );
+               ui::root.alert( m_buffer.c_str(), "Radiant - Runtime Error", ui::alert_type::OK, ui::alert_icon::Error );
                m_buffer.clear();
 #endif
        }
@@ -329,7 +329,7 @@ void paths_init(){
 
        {
                StringOutputStream path( 256 );
-               path << home << "1." << RADIANT_MAJOR_VERSION "." << RADIANT_MINOR_VERSION << '/';
+               path << home << "/";
                g_strSettingsPath = path.c_str();
        }
 
@@ -394,9 +394,9 @@ bool check_version(){
        if ( !bVerIsGood ) {
                StringOutputStream msg( 256 );
                msg << "This editor binary (" RADIANT_VERSION ") doesn't match what the latest setup has configured in this directory\n"
-                                                                                                         "Make sure you run the right/latest editor binary you installed\n"
+                               "Make sure you run the right/latest editor binary you installed\n"
                        << AppPath_get();
-               gtk_MessageBox( 0, msg.c_str(), "Radiant", eMB_OK, eMB_ICONDEFAULT );
+               ui::alert( 0, msg.c_str(), "Radiant", eMB_OK, eMB_ICONDEFAULT );
        }
        return bVerIsGood;
 #else
@@ -424,7 +424,7 @@ void create_global_pid(){
                if ( remove( g_pidFile.c_str() ) == -1 ) {
                        StringOutputStream msg( 256 );
                        msg << "WARNING: Could not delete " << g_pidFile.c_str();
-                       gtk_MessageBox( 0, msg.c_str(), "Radiant", eMB_OK, eMB_ICONERROR );
+                       ui::root.alert( msg.c_str(), "Radiant", ui::alert_type::OK, ui::alert_icon::Error );
                }
 
                // in debug, never prompt to clean registry, turn console logging auto after a failed start
@@ -434,14 +434,14 @@ void create_global_pid(){
                           "The failure may be related to current global preferences.\n"
                           "Do you want to reset global preferences to defaults?";
 
-               if ( gtk_MessageBox( 0, msg.c_str(), "Radiant - Startup Failure", eMB_YESNO, eMB_ICONQUESTION ) == eIDYES ) {
+               if ( ui::root.alert( msg.c_str(), "Radiant - Startup Failure", ui::alert_type::YESNO, ui::alert_icon::QUESTION ) == ui::alert_response::YES ) {
                        g_GamesDialog.Reset();
                }
 
                msg.clear();
                msg << "Logging console output to " << SettingsPath_get() << "radiant.log\nRefer to the log if Radiant fails to start again.";
 
-               gtk_MessageBox( 0, msg.c_str(), "Radiant - Console Log", eMB_OK );
+               ui::root.alert( msg.c_str(), "Radiant - Console Log", ui::alert_type::OK );
 #endif
 
                // set without saving, the class is not in a coherent state yet
@@ -465,7 +465,7 @@ void remove_global_pid(){
        if ( remove( g_pidFile.c_str() ) == -1 ) {
                StringOutputStream msg( 256 );
                msg << "WARNING: Could not delete " << g_pidFile.c_str();
-               gtk_MessageBox( 0, msg.c_str(), "Radiant", eMB_OK, eMB_ICONERROR );
+               ui::root.alert( msg.c_str(), "Radiant", ui::alert_type::OK, ui::alert_icon::Error );
        }
 }
 
@@ -483,7 +483,7 @@ void create_local_pid(){
                if ( remove( g_pidGameFile.c_str() ) == -1 ) {
                        StringOutputStream msg;
                        msg << "WARNING: Could not delete " << g_pidGameFile.c_str();
-                       gtk_MessageBox( 0, msg.c_str(), "Radiant", eMB_OK, eMB_ICONERROR );
+                       ui::root.alert( msg.c_str(), "Radiant", ui::alert_type::OK, ui::alert_icon::Error );
                }
 
                // in debug, never prompt to clean registry, turn console logging auto after a failed start
@@ -493,14 +493,14 @@ void create_local_pid(){
                           "The failure may be caused by current preferences.\n"
                           "Do you want to reset all preferences to defaults?";
 
-               if ( gtk_MessageBox( 0, msg.c_str(), "Radiant - Startup Failure", eMB_YESNO, eMB_ICONQUESTION ) == eIDYES ) {
+               if ( ui::root.alert( msg.c_str(), "Radiant - Startup Failure", ui::alert_type::YESNO, ui::alert_icon::QUESTION ) == ui::alert_response::YES ) {
                        Preferences_Reset();
                }
 
                msg.clear();
                msg << "Logging console output to " << SettingsPath_get() << "radiant.log\nRefer to the log if Radiant fails to start again.";
 
-               gtk_MessageBox( 0, msg.c_str(), "Radiant - Console Log", eMB_OK );
+               ui::root.alert( msg.c_str(), "Radiant - Console Log", ui::alert_type::OK );
 #endif
 
                // force console logging on! (will go in prefs too)
@@ -558,8 +558,38 @@ int main( int argc, char* argv[] ){
        }
 #endif
 
+       static GOptionEntry entries[] = {
+               { NULL }
+       };
+       GError *error = NULL;
+       const char* mapname = NULL;
+
        gtk_disable_setlocale();
-       gtk_init( &argc, &argv );
+       if ( !gtk_init_with_args( &argc, &argv, "<filename.map>", entries, NULL, &error) ) {
+               g_print( "%s\n", error->message );
+               return -1;
+       }
+
+       // Gtk already removed parsed `--options`
+       if (argc == 2) {
+               if ( strlen( argv[1] ) > 1 ) {
+                       if ( g_str_has_suffix( argv[1], ".map" ) ) {
+                               if ( g_path_is_absolute( argv[1] ) ) {
+                                       mapname = argv[1];
+                               }
+                               else {
+                                       mapname = g_build_filename( g_get_current_dir(), argv[1], NULL );
+                               }
+                       }
+                       else {
+                               g_print( "bad file name, will not load: %s\n", argv[1] );
+                       }
+               }
+       }
+       else if (argc > 2) {
+               g_print ( "%s\n", "too many arguments" );
+               return -1;
+       }
 
        // redirect Gtk warnings to the console
        g_log_set_handler( "Gdk", (GLogLevelFlags)( G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING |
@@ -611,8 +641,6 @@ int main( int argc, char* argv[] ){
 
        Radiant_Initialise();
 
-       global_accel_init();
-
        user_shortcuts_init();
 
        g_pParentWnd = 0;
@@ -620,7 +648,10 @@ int main( int argc, char* argv[] ){
 
        hide_splash();
 
-       if ( g_bLoadLastMap && !g_strLastMap.empty() ) {
+       if ( mapname != NULL ) {
+               Map_LoadFile( mapname );
+       }
+       else if ( g_bLoadLastMap && !g_strLastMap.empty() ) {
                Map_LoadFile( g_strLastMap.c_str() );
        }
        else
@@ -635,7 +666,7 @@ int main( int argc, char* argv[] ){
 
        remove_local_pid();
 
-       gtk_main();
+       ui::main();
 
        // avoid saving prefs when the app is minimized
        if ( g_pParentWnd->IsSleeping() ) {
@@ -653,8 +684,6 @@ int main( int argc, char* argv[] ){
 
        user_shortcuts_save();
 
-       global_accel_destroy();
-
        Radiant_Shutdown();
 
        // close the log file if any