Ticket #841: libass_fontupdate_dialog.patch

File libass_fontupdate_dialog.patch, 2.7 KB (added by nielsm, 2 years ago)

Non-working initial patch to add this dialogue

  • src/subtitles_provider_libass.cpp

     
    4646#include "utils.h" 
    4747#include "standard_paths.h" 
    4848#include <wx/filefn.h> 
     49#include <wx/thread.h> 
     50#include <wx/dialog.h> 
     51#include <wx/gauge.h> 
     52#include <wx/utils.h> 
    4953 
    5054#ifdef __APPLE__ 
    5155extern "C" { 
     
    5458} 
    5559#endif 
    5660 
    57 #define STUB_MSG _("Please wait, caching fonts..."); 
    5861 
     62 
     63DEFINE_EVENT_TYPE(AEGISUB_LIBASS_FONTUPDATE_FINISH) 
     64 
     65class AegisubLibassFontupdateFinishEvent : public wxEvent { 
     66public: 
     67        AegisubLibassFontupdateFinishEvent() 
     68                : wxEvent(0, AEGISUB_LIBASS_FONTUPDATE_FINISH) 
     69        { } 
     70        virtual wxEvent *Clone() const { 
     71                return new AegisubLibassFontupdateFinishEvent(*this); 
     72        } 
     73}; 
     74 
     75class LibassFontUpdateThread : public wxThread { 
     76        wxEvtHandler &completion_event_handler; 
     77 
     78public: 
     79        LibassFontUpdateThread(wxEvtHandler &completion_event_handler) 
     80                : wxThread(wxTHREAD_DETACHED) 
     81                , completion_event_handler(completion_event_handler) 
     82        { 
     83                Create(); 
     84                Run(); 
     85        } 
     86 
     87        ExitCode Entry() { 
     88                ass_fonts_update(); 
     89                completeion_event_handler->AddPendingEvent(AegisubLibassFontupdateFinishEvent()); 
     90        } 
     91}; 
     92 
     93 
     94class LibassFontUpdateStatusDialog : public wxDialog, wxTimer { 
     95        void Notify() { 
     96                Show(); 
     97        } 
     98 
     99        bool font_update_running; 
     100 
     101        void OnDoneUpdating(AegisubLibassFontupdateFinishEvent &evt) { 
     102                font_update_running = false; 
     103        } 
     104 
     105public: 
     106        LibassFontUpdateStatusDialog() 
     107                : wxDialog(0, -1, _T(""), wxDefaultPos, wxDefaultSize, 0) 
     108                , wxTimer() 
     109        { 
     110                font_update_running = true; 
     111                 
     112                wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL); 
     113 
     114                main_sizer->Add(new wxStaticText(this, -1, _("Please wait, caching fonts...")), 0, wxEXPAND|wxALL, 12); 
     115 
     116                wxGauge *gauge = new wxGauge(this, -1, 1, wxDefaultPosition, wxSize(350, -1)); 
     117                gauge->Pulse(); 
     118                main_sizer->Add(gauge, 0, wxEXPAND|wxALL&~wxTOP, 12); 
     119 
     120                SetSizerAndFit(main_sizer); 
     121                Centre(); 
     122 
     123                Start(2000, true); 
     124        } 
     125 
     126        void WaitForFontUpdateCompletion() { 
     127                while (app.Pending() || font_update_running) 
     128                { 
     129                        Dispatch(); 
     130                } 
     131                Destroy(); 
     132        } 
     133}; 
     134 
     135 
    59136/////////////// 
    60137// Constructor 
    61138LibassSubtitlesProvider::LibassSubtitlesProvider() { 
     
    93170        const char *config_path = NULL; 
    94171#endif 
    95172 
    96         ass_set_fonts(ass_renderer, NULL, "Sans", 1, config_path, 1); 
     173        ass_set_fonts(ass_renderer, NULL, "Sans", 1, config_path, 0); 
     174 
     175        LibassFontUpdateStatusDialog *fonts_update_dlg = new LibassFontUpdateStatusDialog; 
     176        new LibassFontUpdateThread(fonts_update_dlg); 
     177        wxWindowDisabler win_disabler(fonts_update_dlg); 
     178        fonts_update_dlg->WaitForFontUpdateCompletion(); 
    97179} 
    98180 
    99181