From: Good Guy Date: Tue, 10 Sep 2019 02:40:56 +0000 (-0600) Subject: add file->load_recent mainmenu item, rm timebomb X-Git-Tag: 2019-09~10 X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=commitdiff_plain;h=44f0242e0f313fd1b49675c697629b73dc260d21 add file->load_recent mainmenu item, rm timebomb --- diff --git a/cinelerra-5.1/cinelerra/loadfile.C b/cinelerra-5.1/cinelerra/loadfile.C index 345456d9..fff3b625 100644 --- a/cinelerra-5.1/cinelerra/loadfile.C +++ b/cinelerra-5.1/cinelerra/loadfile.C @@ -251,7 +251,7 @@ LocateFileWindow::~LocateFileWindow() LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile) - : BC_MenuItem(""), Thread() + : BC_MenuItem("") { this->mwindow = mwindow; this->loadfile = loadfile; @@ -259,6 +259,7 @@ LoadPrevious::LoadPrevious(MWindow *mwindow, Load *loadfile) int LoadPrevious::handle_event() { + if( !path[0] ) return 1; ArrayList path_list; path_list.set_array_delete(); char *out_path; @@ -277,14 +278,7 @@ int LoadPrevious::handle_event() return 1; } - - -void LoadPrevious::run() -{ -// loadfile->mwindow->load(path, loadfile->append); -} - -int LoadPrevious::set_path(char *path) +int LoadPrevious::set_path(const char *path) { strcpy(this->path, path); return 0; diff --git a/cinelerra-5.1/cinelerra/loadfile.h b/cinelerra-5.1/cinelerra/loadfile.h index 7d860203..ef1a8e05 100644 --- a/cinelerra-5.1/cinelerra/loadfile.h +++ b/cinelerra-5.1/cinelerra/loadfile.h @@ -92,14 +92,12 @@ public: MWindow *mwindow; }; -class LoadPrevious : public BC_MenuItem, public Thread +class LoadPrevious : public BC_MenuItem { public: LoadPrevious(MWindow *mwindow, Load *loadfile); int handle_event(); - void run(); - - int set_path(char *path); + int set_path(const char *path); MWindow *mwindow; Load *loadfile; diff --git a/cinelerra-5.1/cinelerra/mainmenu.C b/cinelerra-5.1/cinelerra/mainmenu.C index 9fe3c292..f33a5c74 100644 --- a/cinelerra-5.1/cinelerra/mainmenu.C +++ b/cinelerra-5.1/cinelerra/mainmenu.C @@ -97,7 +97,6 @@ void MainMenu::create_objects() { BC_Menu *viewmenu, *windowmenu, *settingsmenu, *trackmenu; PreferencesMenuitem *preferences; - total_loads = 0; add_menu(filemenu = new BC_Menu(_("File"))); filemenu->add_item(new_project = new NewProject(mwindow)); @@ -106,6 +105,8 @@ void MainMenu::create_objects() // file loaders filemenu->add_item(load_file = new Load(mwindow, this)); load_file->create_objects(); + filemenu->add_item(load_recent = new LoadRecent(mwindow, this)); + load_recent->create_objects(); // new and load can be undone so no need to prompt save Save *save; // affected by saveas @@ -383,22 +384,21 @@ int MainMenu::init_veffects(BC_Hash *defaults) void MainMenu::init_loads(BC_Hash *defaults) { - total_loads = defaults->get((char*)"TOTAL_LOADS", 0); - if( !total_loads ) return; - filemenu->add_item(new BC_MenuItem("-")); +// total_loads for legacy xml + int total_loads = defaults->get((char*)"TOTAL_LOADS", 0); + int loads_total = defaults->get((char*)"LOADS_TOTAL", 0); + if( loads_total < total_loads ) loads_total = total_loads; - char string[BCTEXTLEN], path[BCTEXTLEN], filename[BCTEXTLEN]; + char string[BCTEXTLEN], path[BCTEXTLEN]; FileSystem dir; //printf("MainMenu::init_loads 2\n"); - for(int i = 0; i < total_loads; i++) { + for( int i=0; iget(string, path); - filemenu->add_item(load[i] = new LoadPrevious(mwindow, load_file)); - dir.extract_name(filename, path, 0); - load[i]->set_text(filename); - load[i]->set_path(path); + if( load.size() < TOTAL_LOADS ) + load.append(new LoadRecentItem(path)); } } @@ -430,10 +430,13 @@ int MainMenu::save_veffects(BC_Hash *defaults) int MainMenu::save_loads(BC_Hash *defaults) { +// legacy to prevent segv, older code cant tolerate total_loads>10 + int loads_total = load.size(); + int total_loads = MIN(10, loads_total); + defaults->update((char*)"LOADS_TOTAL", loads_total); defaults->update((char*)"TOTAL_LOADS", total_loads); char string[BCTEXTLEN]; - for(int i = 0; i < total_loads; i++) - { + for( int i=0; iupdate(string, load[i]->path); } @@ -528,62 +531,11 @@ int MainMenu::add_veffect(char *title) int MainMenu::add_load(char *path) { - if(total_loads == 0) -{ - filemenu->add_item(new BC_MenuItem("-")); - } - -// test for existing copy - FileSystem fs; - char text[BCTEXTLEN], new_path[BCTEXTLEN]; // get text and path - fs.extract_name(text, path); - strcpy(new_path, path); - - for(int i = 0; i < total_loads; i++) - { - if(!strcmp(load[i]->get_text(), text)) // already exists - { // swap for top load - for(int j = i; j > 0; j--) // move preceeding loads down - { - load[j]->set_text(load[j - 1]->get_text()); - load[j]->set_path(load[j - 1]->path); - } - load[0]->set_text(text); - load[0]->set_path(new_path); - - return 1; - } - } - -// add another load - if(total_loads < TOTAL_LOADS) - { - filemenu->add_item(load[total_loads] = new LoadPrevious(mwindow, load_file)); - total_loads++; - } - -// cycle loads down - for(int i = total_loads - 1; i > 0; i--) - { - // set menu item text - load[i]->set_text(load[i - 1]->get_text()); - // set filename - load[i]->set_path(load[i - 1]->path); - } - -// set up the new load - load[0]->set_text(text); - load[0]->set_path(new_path); - return 0; + return load.add_load(path); } - - - - - // ================================== menu items MainDumpsSubMenu::MainDumpsSubMenu(BC_MenuItem *menu_item) @@ -1938,3 +1890,118 @@ void LoadLayoutConfirm::create_objects() unlock_window(); } + +LoadRecentItem::LoadRecentItem(const char *path) +{ + this->path = cstrdup(path); +} + +LoadRecentItem::~LoadRecentItem() +{ + delete [] path; +} + +int LoadRecentItems::add_load(char *path) +{ +// test for existing copy + FileSystem fs; + char name[BCTEXTLEN], text[BCTEXTLEN]; + fs.extract_name(name, path); + int loads_total = size(); + int ret = 0, k = loads_total; + LoadRecentItem *load_item = 0; + + for( int i=0; !ret && ipath); + if( strcmp(name, text) ) continue; + k = i; ret = 1; // already exists, move to top + } + if( !ret ) { // adding a new one + while( loads_total >= TOTAL_LOADS ) + remove_object_number(--loads_total); + insert(new LoadRecentItem(path), 0); + } + else if( k > 0 ) { // cycle loads + while( --k >= 0 ) set(k+1, get(k)); + set(0, load_item); + } + return ret; +} + +LoadRecentItems::LoadRecentItems() +{ +} + +LoadRecentItems::~LoadRecentItems() +{ + remove_all_objects(); +} + +LoadRecent::LoadRecent(MWindow *mwindow, MainMenu *main_menu) + : BC_MenuItem(_("Load Recent...")) +{ + this->mwindow = mwindow; + this->main_menu = main_menu; + total_items = 0; +} +LoadRecent::~LoadRecent() +{ +} + +void LoadRecent::create_objects() +{ + add_submenu(submenu = new LoadRecentSubMenu(this)); +} + +LoadPrevious *LoadRecent::get_next_item() +{ + int k = total_items++; + if( k < submenu->total_items() ) + return (LoadPrevious *)submenu->get_item(k); + LoadPrevious *load_prev = new LoadPrevious(mwindow, main_menu->load_file); + submenu->add_item(load_prev); + return load_prev; +} + +int LoadRecent::activate_submenu() +{ + total_items = 0; + scan_items(1); + if( total_items > 0 ) { + LoadPrevious *load_prev = get_next_item(); + load_prev->set_text("-"); + load_prev->set_path(""); + } + scan_items(0); + while( total_items < submenu->total_items() ) + submenu->del_item(0); + return BC_MenuItem::activate_submenu(); +} + +void LoadRecent::scan_items(int use_xml) +{ + FileSystem fs; + int loads_total = main_menu->load.size(); + for( int i=0; iload[i]; + char name[BCTEXTLEN]; + fs.extract_name(name, recent->path); + const char *cp = strrchr(name, '.'); + if( !cp || strcasecmp(cp+1,"xml") ? use_xml : !use_xml ) continue; + LoadPrevious *load_prev = get_next_item(); + load_prev->set_text(name); + load_prev->set_path(recent->path); + } +} + +LoadRecentSubMenu::LoadRecentSubMenu(LoadRecent *load_recent) + : BC_SubMenu() +{ + this->load_recent = load_recent; +} + +LoadRecentSubMenu::~LoadRecentSubMenu() +{ +} + diff --git a/cinelerra-5.1/cinelerra/mainmenu.h b/cinelerra-5.1/cinelerra/mainmenu.h index a8833836..9e0513cd 100644 --- a/cinelerra-5.1/cinelerra/mainmenu.h +++ b/cinelerra-5.1/cinelerra/mainmenu.h @@ -41,12 +41,54 @@ #include "threadloader.inc" #include "viewmenu.inc" -#define TOTAL_LOADS 10 // number of files to cache +#define TOTAL_LOADS 20 // number of files to cache #define TOTAL_EFFECTS 10 // number of effects to cache #define LAYOUT_LOAD 0 #define LAYOUT_SAVE 1 +class LoadRecentItem +{ +public: + LoadRecentItem(const char *path); + ~LoadRecentItem(); + char *path; +}; + +class LoadRecentItems : public ArrayList +{ +public: + LoadRecentItems(); + ~LoadRecentItems(); + int add_load(char *path); +}; + +class LoadRecentSubMenu : public BC_SubMenu +{ +public: + LoadRecentSubMenu(LoadRecent *load_recent); + ~LoadRecentSubMenu(); + + LoadRecent *load_recent; +}; + +class LoadRecent : public BC_MenuItem +{ +public: + LoadRecent(MWindow *mwindow, MainMenu *main_menu); + ~LoadRecent(); + void create_objects(); + LoadPrevious *get_next_item(); + int activate_submenu(); + void scan_items(int use_xml); + + MWindow *mwindow; + MainMenu *main_menu; + LoadRecentSubMenu *submenu; + int total_items; +}; + + class MainMenu : public BC_MenuBar { public: @@ -81,8 +123,8 @@ public: MenuVEffects *veffects; Load *load_file; - LoadPrevious *load[TOTAL_LOADS]; - int total_loads; + LoadRecentItems load; + LoadRecent *load_recent; RecordMenuItem *record_menu_item; RenderItem *render; @@ -94,9 +136,9 @@ public: EditClearMenu *clear_menu; Undo *undo; Redo *redo; - int total_aeffects; - int total_veffects; - BC_Menu *filemenu, *audiomenu, *videomenu; // needed by most recents + BC_Menu *filemenu; + BC_Menu *audiomenu, *videomenu; // needed by most recents + int total_aeffects, total_veffects; KeyframeCurveType *keyframe_curve_type; LabelsFollowEdits *labels_follow_edits; diff --git a/cinelerra-5.1/cinelerra/mainmenu.inc b/cinelerra-5.1/cinelerra/mainmenu.inc index e145397e..dbe51384 100644 --- a/cinelerra-5.1/cinelerra/mainmenu.inc +++ b/cinelerra-5.1/cinelerra/mainmenu.inc @@ -24,6 +24,10 @@ #define MENUBARPIXELS 25 +class LoadRecentItem; +class LoadRecentItems; +class LoadRecentSubMenu; +class LoadRecent; class MainMenu; class Undo; class MainDumpsSubMenu; @@ -57,6 +61,7 @@ class PasteSilence; class SelectAll; class ClearHardEdges; class ClearLabels; +class ClearSelect; class CutCommercials; class DetachTransitions; class MuteSelection; diff --git a/cinelerra-5.1/cinelerra/mwindow.h b/cinelerra-5.1/cinelerra/mwindow.h index 24d75790..ff5ea817 100644 --- a/cinelerra-5.1/cinelerra/mwindow.h +++ b/cinelerra-5.1/cinelerra/mwindow.h @@ -88,7 +88,6 @@ #include "thread.h" #include "threadloader.inc" #include "timebar.inc" -#include "timebomb.h" #include "tipwindow.inc" #include "track.inc" #include "tracking.inc" diff --git a/cinelerra-5.1/cinelerra/timebomb.C b/cinelerra-5.1/cinelerra/timebomb.C deleted file mode 100644 index b5897f9c..00000000 --- a/cinelerra-5.1/cinelerra/timebomb.C +++ /dev/null @@ -1,95 +0,0 @@ - -/* - * CINELERRA - * Copyright (C) 2008 Adam Williams - * - * This program 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. - * - * This program 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "timebomb.h" -#include -#include -#include - -#define LASTYEAR 2001 -#define LASTDAY 1 -#define LASTMONTH 10 -#define EXCUSE \ -"To reduce support liability this release had an expiration date.\n" \ -"The expiration date of this release has expired.\n" - -static char *files[] = -{ - "/usr/lib/libcinelerra.so", - "/usr/bin/cinelerra" -}; - -TimeBomb::TimeBomb() -{ - struct stat fileinfo; - time_t system_time; - int result; - - result = stat("/etc", &fileinfo); - system_time = time(0); - -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); -printf("This release expires %d/%d/%d\n", LASTMONTH, LASTDAY, LASTYEAR); - - if(test_time(fileinfo.st_mtime) || - test_time(system_time)) - { - printf(EXCUSE); - disable_system(); - exit(1); - } -} - - -int TimeBomb::test_time(time_t testtime) -{ - struct tm *currenttime; - currenttime = localtime(&testtime); - - if(currenttime->tm_year >= LASTYEAR - 1900 && - currenttime->tm_mday >= LASTDAY && - currenttime->tm_mon >= LASTMONTH - 1) return 1; - else return 0; -} - -void TimeBomb::disable_system() -{ -//printf("TimeBomb::disable_system %d\n", sizeof(files)); - for(int i = 0; i < sizeof(files) / sizeof(char*); i++) - { - remove((const char*)files[i]); - } -} - -TimeBomb::~TimeBomb() -{ -} - diff --git a/cinelerra-5.1/cinelerra/timebomb.h b/cinelerra-5.1/cinelerra/timebomb.h deleted file mode 100644 index 0ac0b07e..00000000 --- a/cinelerra-5.1/cinelerra/timebomb.h +++ /dev/null @@ -1,40 +0,0 @@ - -/* - * CINELERRA - * Copyright (C) 2008 Adam Williams - * - * This program 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. - * - * This program 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef TIMEBOMB_H -#define TIMEBOMB_H - -#include - -class TimeBomb -{ -public: - TimeBomb(); - ~TimeBomb(); - - int test_time(time_t testtime); - void disable_system(); -}; - - - - -#endif