From 5103f8a4f0d969549c08d619d7e468bb3a09020b Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sat, 1 Jul 2006 02:27:37 +0000 Subject: [PATCH] Attachment list dialog implemented, only lists so far. Originally committed to SVN as r443. --- core/ass_file.cpp | 3 +- core/ass_file.h | 2 +- core/bitmaps/attach.bmp | Bin 0 -> 1318 bytes core/changelog.txt | 1 + core/dialog_attachments.cpp | 125 +++++++++++++++++++++++++++++++++++ core/dialog_attachments.h | 76 +++++++++++++++++++++ core/frame_main.cpp | 2 + core/frame_main.h | 2 + core/frame_main_events.cpp | 11 +++ core/res.rc | 1 + core/subtitle_format.cpp | 4 +- core/subtitle_format.h | 2 +- core/subtitle_format_ass.cpp | 2 +- core/utils.cpp | 34 ++++++++++ core/utils.h | 1 + 15 files changed, 260 insertions(+), 6 deletions(-) create mode 100644 core/bitmaps/attach.bmp create mode 100644 core/dialog_attachments.cpp create mode 100644 core/dialog_attachments.h diff --git a/core/ass_file.cpp b/core/ass_file.cpp index 88080c255..d5d73bdab 100644 --- a/core/ass_file.cpp +++ b/core/ass_file.cpp @@ -240,12 +240,13 @@ wxString AssFile::GetString() { // I strongly advice you against touching this function unless you know what you're doing; // even moving things out of order might break ASS parsing - AMZ. // -int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) { +int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA,wxString *outGroup) { // Group AssEntry *entry = NULL; wxString origGroup = group; static wxString keepGroup; if (!keepGroup.IsEmpty()) group = keepGroup; + if (outGroup) *outGroup = group; // Attachment if (group == _T("[Fonts]") || group == _T("[Graphics]")) { diff --git a/core/ass_file.h b/core/ass_file.h index a6bf3eff5..f516f1df9 100644 --- a/core/ass_file.h +++ b/core/ass_file.h @@ -97,7 +97,7 @@ public: wxString GetScriptInfo(const wxString key); // Returns the value in a [Script Info] key. void SetScriptInfo(const wxString key,const wxString value); // Sets the value of a [Script Info] key. Adds it if it doesn't exist. void AddComment(const wxString comment); // Adds a ";" comment under [Script Info]. - int AddLine(wxString data,wxString group,int lasttime,bool &IsSSA); + int AddLine(wxString data,wxString group,int lasttime,bool &IsSSA,wxString *outGroup=NULL); static void StackPop(); // Pop subs from stack and sets 'top' to it static void StackRedo(); // Redoes action on stack diff --git a/core/bitmaps/attach.bmp b/core/bitmaps/attach.bmp new file mode 100644 index 0000000000000000000000000000000000000000..f74928366a195f6a0671a22ebbaae9b561d417cb GIT binary patch literal 1318 zcmaizp=(@05XQg4l{*n=V@}01qV)7YA@=-1Omy7-3o#X^q6>k*x`?(=QIo&mR7ErH zATf<tB^p&6Q`7V9Mqy`eYshThO~ zTSxEcouH$4bOt%PqdU4IIC>BVadpGB%k)Wlv`?7z_r3!B9vr7z_r3!C){H zCJY9H!C){L422GZ!C){L3@y{db_;+g4VdyY)>X64qRqE|g80qsEse$9? zusIx#Umb07Py>g +#include "dialog_attachments.h" +#include "ass_file.h" +#include "ass_attachment.h" +#include "utils.h" + + +/////////////// +// Constructor +DialogAttachments::DialogAttachments(wxWindow *parent) +: wxDialog(parent,-1,_("Attachment List"),wxDefaultPosition,wxDefaultSize) +{ + // List view + listView = new wxListView(this,-1,wxDefaultPosition,wxSize(400,200)); + listView->InsertColumn(0, _("Attachment name"), wxLIST_FORMAT_LEFT, 200); + listView->InsertColumn(1, _("Size"), wxLIST_FORMAT_LEFT, 90); + listView->InsertColumn(2, _("Group"), wxLIST_FORMAT_LEFT, 90); + + // Fill list + AssAttachment *attach; + for (std::list::iterator cur = AssFile::top->Line.begin();cur != AssFile::top->Line.end();cur++) { + attach = AssEntry::GetAsAttachment(*cur); + if (attach) { + // Add item + int row = listView->GetItemCount(); + listView->InsertItem(row,attach->filename); + listView->SetItem(row,1,PrettySize(attach->GetData().size())); + listView->SetItem(row,2,attach->group); + listView->SetItemData(row,(long)attach); + } + } + + // Buttons sizer + wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL); + buttonSizer->Add(new wxButton(this,BUTTON_ATTACH_FONT,_("&Attach Font")),3,0,0); + buttonSizer->Add(new wxButton(this,BUTTON_EXTRACT,_("E&xtract")),2,0,0); + buttonSizer->Add(new wxButton(this,BUTTON_DELETE,_("&Delete")),2,0,0); + buttonSizer->Add(new wxButton(this,BUTTON_CLOSE,_("&Close")),2,wxLEFT,5); + + // Main sizer + wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); + mainSizer->Add(listView,1,wxTOP | wxLEFT | wxRIGHT | wxEXPAND,5); + mainSizer->Add(buttonSizer,0,wxALL | wxEXPAND,5); + mainSizer->SetSizeHints(this); + SetSizer(mainSizer); +} + + +////////////// +// Destructor +DialogAttachments::~DialogAttachments() { +} + + +/////////////// +// Event table +BEGIN_EVENT_TABLE(DialogAttachments,wxDialog) + EVT_BUTTON(BUTTON_ATTACH_FONT,DialogAttachments::OnAttachFont) + EVT_BUTTON(BUTTON_EXTRACT,DialogAttachments::OnExtract) + EVT_BUTTON(BUTTON_DELETE,DialogAttachments::OnDelete) + EVT_BUTTON(BUTTON_CLOSE,DialogAttachments::OnClose) +END_EVENT_TABLE() + + +/////////////// +// Attach font +void DialogAttachments::OnAttachFont(wxCommandEvent &event) { +} + + +/////////// +// Extract +void DialogAttachments::OnExtract(wxCommandEvent &event) { +} + + +////////// +// Delete +void DialogAttachments::OnDelete(wxCommandEvent &event) { +} + + +///////// +// Close +void DialogAttachments::OnClose(wxCommandEvent &event) { + EndModal(0); +} diff --git a/core/dialog_attachments.h b/core/dialog_attachments.h new file mode 100644 index 000000000..413b7e369 --- /dev/null +++ b/core/dialog_attachments.h @@ -0,0 +1,76 @@ +// Copyright (c) 2006, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +#pragma once + + +/////////// +// Headers +#include + + +////////////// +// Prototypes +class wxListView; + + +////////////////////// +// Attachments window +class DialogAttachments : public wxDialog { +private: + wxListView *listView; + + void OnAttachFont(wxCommandEvent &event); + void OnExtract(wxCommandEvent &event); + void OnDelete(wxCommandEvent &event); + void OnClose(wxCommandEvent &event); + +public: + DialogAttachments(wxWindow *parent); + ~DialogAttachments(); + + DECLARE_EVENT_TABLE() +}; + + +/////// +// IDs +enum { + BUTTON_ATTACH_FONT = 1300, + BUTTON_EXTRACT, + BUTTON_DELETE, + BUTTON_CLOSE +}; diff --git a/core/frame_main.cpp b/core/frame_main.cpp index 2e2e085bc..8a4d655b1 100644 --- a/core/frame_main.cpp +++ b/core/frame_main.cpp @@ -173,6 +173,7 @@ void FrameMain::InitToolbar () { // Property stuff Toolbar->AddTool(Menu_Tools_Properties,_("Properties"),wxBITMAP(properties_toolbutton),_("Open Properties")); Toolbar->AddTool(Menu_Tools_Styles_Manager,_("Styles Manager"),wxBITMAP(style_toolbutton),_("Open Styles Manager")); + Toolbar->AddTool(Menu_Tools_Attachments,_("Attachments"),wxBITMAP(attach_button),_("Open Attachment List")); Toolbar->AddSeparator(); // Automation @@ -299,6 +300,7 @@ void FrameMain::InitMenu() { toolMenu = new wxMenu(); AppendBitmapMenuItem (toolMenu,Menu_Tools_Properties, _("&Properties..."), _("Open script properties window"),wxBITMAP(properties_toolbutton)); AppendBitmapMenuItem (toolMenu,Menu_Tools_Styles_Manager, _("&Styles Manager..."), _("Open styles manager"), wxBITMAP(style_toolbutton)); + AppendBitmapMenuItem (toolMenu,Menu_Tools_Attachments, _("&Attachments..."), _("Open the attachment list"), wxBITMAP(attach_button)); toolMenu->AppendSeparator(); AppendBitmapMenuItem (toolMenu,Menu_Tools_Automation, _("&Automation..."),_("Open automation manager"), wxBITMAP(automation_toolbutton)); toolMenu->AppendSeparator(); diff --git a/core/frame_main.h b/core/frame_main.h index cbc2b48b0..98158fec5 100644 --- a/core/frame_main.h +++ b/core/frame_main.h @@ -182,6 +182,7 @@ private: void OnShift (wxCommandEvent &event); void OnOpenProperties (wxCommandEvent &event); void OnOpenStylesManager (wxCommandEvent &event); + void OnOpenAttachments (wxCommandEvent &event); void OnOpenTranslation (wxCommandEvent &event); void OnOpenSpellCheck (wxCommandEvent &event); void OnOpenFontsCollector (wxCommandEvent &event); @@ -312,6 +313,7 @@ enum { Menu_Tools_Properties, Menu_Tools_Styles_Manager, + Menu_Tools_Attachments, Menu_Tools_Translation, Menu_Tools_SpellCheck, Menu_Tools_Fonts_Collector, diff --git a/core/frame_main_events.cpp b/core/frame_main_events.cpp index 82f9d8510..f3ea6f00f 100644 --- a/core/frame_main_events.cpp +++ b/core/frame_main_events.cpp @@ -57,6 +57,7 @@ #include "subs_edit_box.h" #include "options.h" #include "dialog_properties.h" +#include "dialog_attachments.h" #include "main.h" #include "fonts_collector.h" #include "about.h" @@ -166,6 +167,7 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame) EVT_MENU(Menu_Tools_Properties, FrameMain::OnOpenProperties) EVT_MENU(Menu_Tools_Styles_Manager, FrameMain::OnOpenStylesManager) + EVT_MENU(Menu_Tools_Attachments, FrameMain::OnOpenAttachments) EVT_MENU(Menu_Tools_Translation, FrameMain::OnOpenTranslation) EVT_MENU(Menu_Tools_SpellCheck, FrameMain::OnOpenSpellCheck) EVT_MENU(Menu_Tools_Fonts_Collector, FrameMain::OnOpenFontsCollector) @@ -700,6 +702,15 @@ void FrameMain::OnOpenStylesManager(wxCommandEvent& WXUNUSED(event)) { } +//////////////////// +// Open attachments +void FrameMain::OnOpenAttachments(wxCommandEvent& WXUNUSED(event)) { + videoBox->videoDisplay->Stop(); + DialogAttachments attachments(this); + attachments.ShowModal(); +} + + ////////////////////////////// // Open translation assistant void FrameMain::OnOpenTranslation(wxCommandEvent& WXUNUSED(event)) { diff --git a/core/res.rc b/core/res.rc index f002c7642..3f28277cd 100644 --- a/core/res.rc +++ b/core/res.rc @@ -51,6 +51,7 @@ zoom_in_button BITMAP "bitmaps/zoom_in.bmp" zoom_out_button BITMAP "bitmaps/zoom_out.bmp" font_collector_button BITMAP "bitmaps/fontcollect.bmp" hotkeys_button BITMAP "bitmaps/hotkeys.bmp" +attach_button BITMAP "bitmaps/attach.bmp" substart_to_video BITMAP "bitmaps/substart_to_video.bmp" subend_to_video BITMAP "bitmaps/subend_to_video.bmp" video_to_substart BITMAP "bitmaps/video_to_substart.bmp" diff --git a/core/subtitle_format.cpp b/core/subtitle_format.cpp index 3826b46eb..1a313e77e 100644 --- a/core/subtitle_format.cpp +++ b/core/subtitle_format.cpp @@ -111,8 +111,8 @@ void SubtitleFormat::LoadDefault() { //////////// // Add line -int SubtitleFormat::AddLine(wxString data,wxString group,int lasttime,bool &IsSSA) { - return assFile->AddLine(data,group,lasttime,IsSSA); +int SubtitleFormat::AddLine(wxString data,wxString group,int lasttime,bool &IsSSA,wxString *outgroup) { + return assFile->AddLine(data,group,lasttime,IsSSA,outgroup); } diff --git a/core/subtitle_format.h b/core/subtitle_format.h index 75f49a046..b391f448f 100644 --- a/core/subtitle_format.h +++ b/core/subtitle_format.h @@ -70,7 +70,7 @@ protected: void Clear(); void LoadDefault(); AssFile *GetAssFile() { return assFile; } - int AddLine(wxString data,wxString group,int lasttime,bool &IsSSA); + int AddLine(wxString data,wxString group,int lasttime,bool &IsSSA,wxString *outgroup=NULL); public: SubtitleFormat(); diff --git a/core/subtitle_format_ass.cpp b/core/subtitle_format_ass.cpp index 62a917bca..455f2dcfb 100644 --- a/core/subtitle_format_ass.cpp +++ b/core/subtitle_format_ass.cpp @@ -78,7 +78,7 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) { // Add line try { - lasttime = AddLine(wxbuffer,curgroup,lasttime,IsSSA); + lasttime = AddLine(wxbuffer,curgroup,lasttime,IsSSA,&curgroup); } catch (const wchar_t *err) { Clear(); diff --git a/core/utils.cpp b/core/utils.cpp index 9f436347f..407b1588c 100644 --- a/core/utils.cpp +++ b/core/utils.cpp @@ -144,3 +144,37 @@ wxString FloatToString(double value) { wxString IntegerToString(int value) { return wxString::Format(_T("%i"),value); } + + +////////////////////////// +// Pretty reading of size +// There shall be no kiB, MiB stuff here +wxString PrettySize(int bytes) { + // Suffixes + wxArrayString suffix; + suffix.Add(_T("")); + suffix.Add(_T(" kB")); + suffix.Add(_T(" MB")); + suffix.Add(_T(" GB")); + suffix.Add(_T(" TB")); + suffix.Add(_T(" PB")); + + // Set size + int i = 0; + double size = bytes; + while (size > 1024) { + size = size / 1024.0; + i++; + if (i == 6) { + i--; + break; + } + } + + // Set number of decimal places + wxString final; + if (size < 10) final = wxString::Format(_T("%.2f"),size); + else if (size < 100) final = wxString::Format(_T("%.1f"),size); + else final = wxString::Format(_T("%.0f"),size); + return final + suffix[i]; +} diff --git a/core/utils.h b/core/utils.h index 5be9bc0bd..c903258e6 100644 --- a/core/utils.h +++ b/core/utils.h @@ -47,6 +47,7 @@ wxString DecodeRelativePath(wxString path,wxString reference); wxString PrettyFloat(wxString src); wxString FloatToString(double value); wxString IntegerToString(int value); +wxString PrettySize(int bytes); //////////