~ubuntu-branches/ubuntu/trusty/aegisub/trusty

« back to all changes in this revision

Viewing changes to src/help_button.cpp

  • Committer: Package Import Robot
  • Author(s): Sebastian Reichel
  • Date: 2012-03-16 22:58:00 UTC
  • Revision ID: package-import@ubuntu.com-20120316225800-yfb8h9e5n04rk46a
Tags: upstream-2.1.9
ImportĀ upstreamĀ versionĀ 2.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2007, Rodrigo Braz Monteiro
 
2
// All rights reserved.
 
3
//
 
4
// Redistribution and use in source and binary forms, with or without
 
5
// modification, are permitted provided that the following conditions are met:
 
6
//
 
7
//   * Redistributions of source code must retain the above copyright notice,
 
8
//     this list of conditions and the following disclaimer.
 
9
//   * Redistributions in binary form must reproduce the above copyright notice,
 
10
//     this list of conditions and the following disclaimer in the documentation
 
11
//     and/or other materials provided with the distribution.
 
12
//   * Neither the name of the Aegisub Group nor the names of its contributors
 
13
//     may be used to endorse or promote products derived from this software
 
14
//     without specific prior written permission.
 
15
//
 
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
21
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
26
// POSSIBILITY OF SUCH DAMAGE.
 
27
//
 
28
// -----------------------------------------------------------------------------
 
29
//
 
30
// AEGISUB
 
31
//
 
32
// Website: http://aegisub.cellosoft.com
 
33
// Contact: mailto:zeratul@cellosoft.com
 
34
//
 
35
 
 
36
 
 
37
///////////
 
38
// Headers
 
39
#include "config.h"
 
40
 
 
41
#include <wx/wxprec.h>
 
42
#include <wx/mimetype.h>
 
43
#include <wx/log.h>
 
44
#include <wx/filename.h>
 
45
#include <map>
 
46
#include "help_button.h"
 
47
#include "utils.h"
 
48
#include "standard_paths.h"
 
49
 
 
50
 
 
51
///////////////
 
52
// Constructor
 
53
HelpButton::HelpButton(wxWindow *parent,wxString _page,wxPoint position,wxSize size)
 
54
: wxButton (parent,wxID_HELP,_T(""),position,size)
 
55
{
 
56
        id = _page;
 
57
        Connect(GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(HelpButton::OnPressed));
 
58
}
 
59
 
 
60
 
 
61
///////////
 
62
// Pressed
 
63
void HelpButton::OnPressed(wxCommandEvent &event) {
 
64
        // Verify if the page is valid
 
65
        if (id.IsEmpty()) {
 
66
                wxLogMessage(_T("TODO"));
 
67
                return;
 
68
        }
 
69
 
 
70
        // Open
 
71
        OpenPage(id);
 
72
}
 
73
 
 
74
 
 
75
///////////////
 
76
// Open a page
 
77
void HelpButton::OpenPage(const wxString pageID) {
 
78
        // Translate ID to page filename
 
79
        InitStatic();
 
80
        wxString page = (*pages)[pageID];
 
81
 
 
82
        wxFileName docFile(StandardPaths::DecodePath(_T("?data/docs/")), page, _T("html"), wxPATH_NATIVE);
 
83
 
 
84
        wxString url;
 
85
        // If we can read a file by the constructed name, assume we have a local copy of the manual
 
86
        if (docFile.IsFileReadable())
 
87
                // Tested IE8, Firefox 3.5, Safari 4, Chrome 4 and Opera 10 on Windows, they all handle
 
88
                // various variations of slashes, missing one at the start and using backslashes throughout
 
89
                // is safe with everything everyone uses. Blame Microsoft.
 
90
                url = wxString(_T("file://")) + docFile.GetFullPath(wxPATH_NATIVE);
 
91
        else
 
92
                url = wxString::Format(_T("http://docs.aegisub.org/manual/%s"),page.c_str());
 
93
 
 
94
        wxLaunchDefaultBrowser(url);
 
95
}
 
96
 
 
97
 
 
98
//////////////
 
99
// Static map
 
100
std::map<wxString,wxString> *HelpButton::pages = NULL;
 
101
 
 
102
void HelpButton::InitStatic() {
 
103
        if (!pages) {
 
104
                pages = new std::map<wxString,wxString>;
 
105
                std::map<wxString,wxString> &page = *pages;
 
106
                page[_T("Attachment Manager")] = _T("Attachment_Manager");
 
107
                page[_T("Automation Manager")] = _T("Automation_Manager");
 
108
                page[_T("Colour Picker")] = _T("Colour_Picker");
 
109
                page[_T("Dummy Video")] = _T("Dummy_video");
 
110
                page[_T("Export")] = _T("Exporting");
 
111
                page[_T("Fonts Collector")] = _T("Fonts_Collector");
 
112
                page[_T("Kanji Timer")] = _T("Kanji_Timer");
 
113
                page[_T("Main")] = _T("Main_Page");
 
114
                page[_T("Options")] = _T("Options");
 
115
                page[_T("Paste Over")] = _T("Paste_Over");
 
116
                page[_T("Properties")] = _T("Properties");
 
117
                page[_T("Resample resolution")] = _T("Resolution_Resampler");
 
118
                page[_T("Shift Times")] = _T("Shift_Times");
 
119
                page[_T("Select Lines")] = _T("Select_Lines");
 
120
                page[_T("Spell Checker")] = _T("Spell_Checker");
 
121
                page[_T("Style Editor")] = _T("Styles");
 
122
                page[_T("Styles Manager")] = _T("Styles");
 
123
                page[_T("Styling Assistant")] = _T("Styling_Assistant");
 
124
                page[_T("Timing Processor")] = _T("Timing_Post-Processor");
 
125
                page[_T("Translation Assistant")] = _T("Translation_Assistant");
 
126
                page[_T("Visual Typesetting")] = _T("Visual_Typesetting");
 
127
        }
 
128
}
 
129
 
 
130
void HelpButton::ClearPages() {
 
131
        if (pages) delete pages;
 
132
}