titler fixes, auto paste bug, resize popup hang, focus policy fix, chk lang
[goodguy/history.git] / cinelerra-5.1 / cinelerra / mwindow.C
index 156c9532abfb3742ae1e82987db95bdfdefd9408..d02fe0bbc1ae53894840d4e566af3e3eb22c81a2 100644 (file)
@@ -29,6 +29,7 @@
 #include "bcdisplayinfo.h"
 #include "bcsignals.h"
 #include "bctimer.h"
+#include "bctrace.h"
 #include "bdcreate.h"
 #include "brender.h"
 #include "cache.h"
@@ -175,6 +176,7 @@ Commercials* MWindow::commercials = 0;
 MWindow::MWindow()
  : Thread(1, 0, 0)
 {
+       run_lock = new Mutex("MWindow::run_lock");
        plugin_gui_lock = new Mutex("MWindow::plugin_gui_lock");
        dead_plugin_lock = new Mutex("MWindow::dead_plugin_lock");
        vwindows_lock = new Mutex("MWindow::vwindows_lock");
@@ -226,9 +228,8 @@ MWindow::MWindow()
 // Need to delete brender temporary here.
 MWindow::~MWindow()
 {
+       run_lock->lock("MWindow::~MWindow");
        in_destructor = 1;
-       stop_playback(1);
-       stop_brender();
 //printf("MWindow::~MWindow %d\n", __LINE__);
        gui->stop_drawing();
        gui->remote_control->deactivate();
@@ -236,9 +237,6 @@ MWindow::~MWindow()
 #ifdef HAVE_DVB
        gui->channel_info->stop();
 #endif
-       brender_lock->lock("MWindow::quit");
-       delete brender;         brender = 0;
-       brender_lock->unlock();
        delete create_bd;       create_bd = 0;
        delete create_dvd;      create_dvd = 0;
        delete batch_render;    batch_render = 0;
@@ -341,23 +339,13 @@ MWindow::~MWindow()
        interlace_asset_fixmethods.remove_all_objects();
        sighandler->terminate();
        delete sighandler;
+       delete run_lock;
 }
 
 
-void MWindow::quit(int unlock)
+void MWindow::quit()
 {
-       if(unlock) gui->unlock_window();
-       stop_playback(1);
-
-       brender_lock->lock("MWindow::quit");
-       delete brender;         brender = 0;
-       brender_lock->unlock();
-
-       interrupt_indexes();
-       clean_indexes();
-       save_defaults();
        gui->set_done(0);
-       if(unlock) gui->lock_window("MWindow::quit");
 }
 
 void MWindow::init_error()
@@ -473,6 +461,32 @@ void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
        defaults->load();
 }
 
+
+void MWindow::check_language()
+{
+       char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
+       const char *env_lang = getenv("LANGUAGE");
+       if( !env_lang ) env_lang = getenv("LANG");
+       if( !env_lang ) {
+               snprintf(curr_lang, sizeof(curr_lang), "%s-%s.%s",
+                       BC_Resources::language, BC_Resources::region, BC_Resources::encoding);
+               env_lang = curr_lang;
+       }
+       char last_lang[BCTEXTLEN]; last_lang[0] = 0;
+       defaults->get("LAST_LANG",last_lang);
+       if( strcmp(env_lang,last_lang)) {
+               printf("lang changed from '%s' to '%s'\n", last_lang, env_lang);
+               defaults->update("LAST_LANG",env_lang);
+               char plugin_path[BCTEXTLEN];
+               create_defaults_path(plugin_path, PLUGIN_FILE);
+               ::remove(plugin_path);
+               char ladspa_path[BCTEXTLEN];
+               create_defaults_path(ladspa_path, LADSPA_FILE);
+               ::remove(ladspa_path);
+               defaults->save();
+       }
+}
+
 void MWindow::get_plugin_path(char *path, const char *plug_dir, const char *fs_path)
 {
        char *base_path = FileSystem::basepath(fs_path), *bp = base_path;
@@ -611,6 +625,7 @@ int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
                len = !cp ? strlen(path) : cp-path;
                char index_path[BCTEXTLEN], plugin_path[BCTEXTLEN];
                memcpy(plugin_path, path, len);  plugin_path[len] = 0;
+               if( cp ) ++len;
                char *plugin_dir = FileSystem::basepath(plugin_path);
                strcpy(plugin_path, plugin_dir);  delete [] plugin_dir;
                create_defaults_path(index_path, LADSPA_FILE);
@@ -797,11 +812,17 @@ void MWindow::init_preferences()
        session->load_defaults(defaults);
        // set x11_host, screens, window_config
        screens = session->set_default_x11_host();
-       BC_Signals::set_trap_path("/tmp/cinelerra_%d.dmp");
        BC_Signals::set_trap_hook(trap_hook, this);
        BC_Signals::set_catch_segv(preferences->trap_sigsegv);
        BC_Signals::set_catch_intr(preferences->trap_sigintr);
+       if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
+               BC_Trace::enable_locks();
+       }
+       else {
+               BC_Trace::disable_locks();
+       }
        BC_WindowBase::get_resources()->popupmenu_btnup = preferences->popupmenu_btnup;
+       BC_WindowBase::get_resources()->textbox_focus_policy = preferences->textbox_focus_policy;
 }
 
 void MWindow::clean_indexes()
@@ -1069,21 +1090,21 @@ void MWindow::init_menus()
                            interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
 
        // Interlacing Modes
-       ILACEASSETMODELISTADD(BC_ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
+       ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
 
-       ILACEASSETMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
-       ILACEPROJECTMODELISTADD(BC_ILACE_MODE_TOP_FIRST);
+       ILACEASSETMODELISTADD(ILACE_MODE_TOP_FIRST);
+       ILACEPROJECTMODELISTADD(ILACE_MODE_TOP_FIRST);
 
-       ILACEASSETMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
-       ILACEPROJECTMODELISTADD(BC_ILACE_MODE_BOTTOM_FIRST);
+       ILACEASSETMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
+       ILACEPROJECTMODELISTADD(ILACE_MODE_BOTTOM_FIRST);
 
-       ILACEASSETMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
-       ILACEPROJECTMODELISTADD(BC_ILACE_MODE_NOTINTERLACED);
+       ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
+       ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
 
        // Interlacing Fixing Methods
-       ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_NONE);
-       ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_UPONE);
-       ILACEFIXMETHODLISTADD(BC_ILACE_FIXMETHOD_DOWNONE);
+       ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
+       ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
+       ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
 }
 
 void MWindow::init_indexes()
@@ -1104,7 +1125,7 @@ void MWindow::init_gui()
 void MWindow::init_signals()
 {
        sighandler = new SigHandler;
-       sighandler->initialize();
+       sighandler->initialize("/tmp/cinelerra_%d.dmp");
 ENABLE_BUFFER
 }
 
@@ -1177,9 +1198,16 @@ int MWindow::brender_available(int position)
        return result;
 }
 
-void MWindow::set_brender_start()
+void MWindow::set_brender_range()
 {
        edl->session->brender_start = edl->local_session->get_selectionstart(1);
+       edl->session->brender_end = edl->local_session->get_selectionend(1);
+
+       if(EQUIV(edl->session->brender_end, edl->session->brender_start))
+       {
+               edl->session->brender_end = edl->tracks->total_video_length();
+       }
+
        restart_brender();
        gui->draw_overlays(1);
 }
@@ -1890,6 +1918,7 @@ void MWindow::create_objects(int want_gui,
        if(debug) PRINT_TRACE
        default_standard = default_std();
        init_defaults(defaults, config_path);
+       check_language();
        init_preferences();
        if(splash_window)
                splash_window->operation->update(_("Initializing Plugins"));
@@ -2097,7 +2126,18 @@ ENABLE_BUFFER
 
 void MWindow::run()
 {
+       run_lock->lock("MWindow::run");
        gui->run_window();
+       stop_playback(1);
+
+       brender_lock->lock("MWindow::run 1");
+       delete brender;         brender = 0;
+       brender_lock->unlock();
+
+       interrupt_indexes();
+       clean_indexes();
+       save_defaults();
+       run_lock->unlock();
 }
 
 void MWindow::show_vwindow()
@@ -2459,8 +2499,8 @@ SET_TRACE
 // Needs mwindow to do GUI
                        gui->set_mwindow(this);
                        gui->open_plugin(0, preferences, edl, plugin);
-                       gui->show_gui();
                        plugin->show = 1;
+                       gui->show_gui();
                }
        }
        plugin_gui_lock->unlock();
@@ -3533,7 +3573,7 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
                                        next_edit = edit->next;
                                        if( edit->channel != vstream ||
                                            !edit->asset || !edit->asset->is_asset ||
-                                           *asset != *edit->asset )
+                                           !asset->equivalent(*edit->asset,1,1,edl) )
                                                delete edit;
                                }
                        }
@@ -3593,7 +3633,7 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
                                        next_edit = edit->next;
                                        if( !((1<<edit->channel) & channel_mask) ||
                                            !edit->asset || !edit->asset->is_asset ||
-                                           *asset != *edit->asset )
+                                           !asset->equivalent(*edit->asset,1,1,edl) )
                                                delete edit;
                                }
                                if( !track->edits->first )