OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Attributes | List of all members
UserManualCmd Class Reference

#include <UserManualCmd.hh>

Inheritance diagram for UserManualCmd:
Inheritance graph
Collaboration diagram for UserManualCmd:
Collaboration graph

Public Member Functions

 UserManualCmd ()
 
virtual ~UserManualCmd ()
 
virtual bool Do ()
 
virtual int id () const
 
virtual UserManualCmdcreate () const
 
virtual std::string icon () const
 
virtual std::string shortName () const
 
virtual bool isEnabled ()
 
- Public Member Functions inherited from GUICommand
 GUICommand (std::string name, wxWindow *parent)
 
virtual ~GUICommand ()
 
virtual bool isChecked () const
 
void setParentWindow (wxWindow *view)
 
wxWindow * parentWindow () const
 
std::string name () const
 

Static Public Attributes

static const std::string COMMAND_NAME = "User Manual"
 Command name string.
 
static const std::string COMMAND_SHORT_NAME = "Help"
 Short version of the command name string.
 
static const std::string COMMAND_ICON = "help.png"
 Command icon file name.
 
static const int COMMAND_ID = 30000
 Command ID.
 

Private Member Functions

bool askFromUser ()
 

Static Private Attributes

static bool mimeTypesManagerInitialized_ = false
 Tells if the singleton mime types manager has already been initialized.
 

Detailed Description

wxCommand for displaying the TCE manual in the system's default PDF viewer.

Definition at line 40 of file UserManualCmd.hh.

Constructor & Destructor Documentation

◆ UserManualCmd()

UserManualCmd::UserManualCmd ( )

The Constructor.

Definition at line 60 of file UserManualCmd.cc.

60 :
62}
static const std::string COMMAND_NAME
Command name string.

Referenced by create().

◆ ~UserManualCmd()

UserManualCmd::~UserManualCmd ( )
virtual

The Destructor.

Definition at line 68 of file UserManualCmd.cc.

68{}

Member Function Documentation

◆ askFromUser()

bool UserManualCmd::askFromUser ( )
private

Fall back function which is called if a default pdf viewer is not found.

Returns
True, if the user chose a pdf viewer.

Definition at line 216 of file UserManualCmd.cc.

216 {
217
219 wxString extension = manual.AfterLast(_T('.'));
220 wxString message = _T("No default PDF viewer found.");
221 message.Append(_T("Please select an executable program to view PDF "));
222 message.Append(_T("files with."));
223 assert(parentWindow() != NULL);
224 ErrorDialog errorDialog(parentWindow(), message);
225 errorDialog.ShowModal();
226
227 wxFileDialog execDialog(
228 parentWindow(), _T("Choose a pdf viewer executable"), _T(""), _T(""),
229 _T("*"), wxOPEN);
230
231 if (execDialog.ShowModal() == wxID_OK) {
232 wxString command = execDialog.GetPath();
233 command.Append(_T(" "));
234 command.Append(manual);
235 wxExecute(command);
236 return true;
237 }
238
239 return false;
240}
#define assert(condition)
static std::string pdfManual()
wxWindow * parentWindow() const
Definition GUICommand.cc:75
static wxString toWxString(const std::string &source)

References assert, GUICommand::parentWindow(), Environment::pdfManual(), and WxConversion::toWxString().

Referenced by Do().

Here is the call graph for this function:

◆ create()

UserManualCmd * UserManualCmd::create ( ) const
virtual

Creates and returns a new instance of this command.

Implements GUICommand.

Definition at line 176 of file UserManualCmd.cc.

176 {
177 return new UserManualCmd();
178}

References UserManualCmd().

Here is the call graph for this function:

◆ Do()

bool UserManualCmd::Do ( )
virtual

Executes the command.

Returns
True, if the command was succesfully executed, false otherwise.

Implements GUICommand.

Definition at line 77 of file UserManualCmd.cc.

77 {
78
79
81 wxTheMimeTypesManager->Initialize();
83 }
84
86 wxString extension = manual.AfterLast(_T('.'));
87 wxFileType* ft =
88 wxTheMimeTypesManager->GetFileTypeFromExtension(extension);
89
90 std::string cmdStr;
91 wxString cmd;
92 if (ft != NULL) {
93 cmd = ft->GetOpenCommand(manual);
94 delete ft;
95 ft = NULL;
96 cmdStr = std::string(cmd.ToAscii());
97 }
98
99 // Stupid hack for now. For fedora some reason this cmd would end up
100 // being 'gimp' which is not very nice PDF reader ;)
101 // on ubuntu this could be gv which cannot view PDF's.
102 if (!(cmdStr.find("evince") != std::string::npos ||
103 cmdStr.find("kpdf") != std::string::npos ||
104 cmdStr.find("kghostview") != std::string::npos ||
105 cmdStr.find("acroread") != std::string::npos ||
106 cmdStr.find("okular") != std::string::npos)) {
107 cmdStr = "";
108 }
109 if (cmdStr == "") {
110 // if couldn't get viewer from mime types test if some usual
111 // default viewer is found
112 std::vector<std::string> viewers;
113 viewers.push_back("/usr/bin/evince");
114 viewers.push_back("/usr/bin/kpdf");
115 viewers.push_back("/usr/bin/kghostview");
116 viewers.push_back("/usr/bin/acroread");
117 viewers.push_back("/usr/bin/okular");
118 for (unsigned int i = 0; i < viewers.size(); ++i) {
119 if (FileSystem::fileIsExecutable(viewers.at(i))) {
120 wxExecute(
121 wxString::FromAscii(
122 (viewers.at(i) + " ").c_str()) + manual);
123 return true;
124 }
125 }
126
127 // if none of above viewers were found try to find from PATH env
128 // variable
129 viewers.clear();
131 viewers.push_back("evince");
132 viewers.push_back("kpdf");
133 viewers.push_back("kghostview");
134 viewers.push_back("acroread");
135 viewers.push_back("okular");
136
137 std::vector<std::string> paths;
138 std::string pathsEnv = Environment::environmentVariable("PATH");
139 StringTools::chopString(pathsEnv, ":", paths);
140
141 for (unsigned int i = 0; i < paths.size(); ++i) {
142 for (unsigned int j = 0; j < viewers.size(); ++j) {
143 std::string viewer = paths.at(i) + DS + viewers.at(j);
144 if (FileSystem::fileIsExecutable(viewer)) {
145 wxExecute(
146 wxString::FromAscii(
147 (viewers.at(i) + " ").c_str()) + manual);
148 return true;
149 }
150 }
151 }
152 // did not find any viewer from path or default locations
153
154 return askFromUser();
155 } else {
156 wxExecute(cmd);
157 }
158
159 return true;
160}
#define DS
static std::string environmentVariable(const std::string &variable)
static bool fileIsExecutable(const std::string fileName)
static const std::string DIRECTORY_SEPARATOR
static std::vector< TCEString > chopString(const std::string &source, const std::string &delimiters)
static bool mimeTypesManagerInitialized_
Tells if the singleton mime types manager has already been initialized.

References askFromUser(), StringTools::chopString(), FileSystem::DIRECTORY_SEPARATOR, DS, Environment::environmentVariable(), FileSystem::fileIsExecutable(), mimeTypesManagerInitialized_, Environment::pdfManual(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ icon()

string UserManualCmd::icon ( ) const
virtual

Returns path to the command's icon file.

Implements GUICommand.

Definition at line 194 of file UserManualCmd.cc.

194 {
195 return COMMAND_ICON;
196}
static const std::string COMMAND_ICON
Command icon file name.

References COMMAND_ICON.

◆ id()

int UserManualCmd::id ( ) const
virtual

Returns id of this command.

Implements GUICommand.

Definition at line 167 of file UserManualCmd.cc.

167 {
168 return COMMAND_ID;
169}
static const int COMMAND_ID
Command ID.

References COMMAND_ID.

◆ isEnabled()

bool UserManualCmd::isEnabled ( )
virtual

This command is always executable.

Returns
Always true.

Implements GUICommand.

Definition at line 205 of file UserManualCmd.cc.

205 {
206 return true;
207}

◆ shortName()

string UserManualCmd::shortName ( ) const
virtual

Returns short version of the command name.

Reimplemented from GUICommand.

Definition at line 185 of file UserManualCmd.cc.

185 {
186 return COMMAND_SHORT_NAME;
187}
static const std::string COMMAND_SHORT_NAME
Short version of the command name string.

References COMMAND_SHORT_NAME.

Member Data Documentation

◆ COMMAND_ICON

const std::string UserManualCmd::COMMAND_ICON = "help.png"
static

Command icon file name.

Definition at line 56 of file UserManualCmd.hh.

Referenced by icon().

◆ COMMAND_ID

const int UserManualCmd::COMMAND_ID = 30000
static

◆ COMMAND_NAME

const std::string UserManualCmd::COMMAND_NAME = "User Manual"
static

Command name string.

Definition at line 52 of file UserManualCmd.hh.

Referenced by ProDe::createDefaultOptions().

◆ COMMAND_SHORT_NAME

const std::string UserManualCmd::COMMAND_SHORT_NAME = "Help"
static

Short version of the command name string.

Definition at line 54 of file UserManualCmd.hh.

Referenced by shortName().

◆ mimeTypesManagerInitialized_

bool UserManualCmd::mimeTypesManagerInitialized_ = false
staticprivate

Tells if the singleton mime types manager has already been initialized.

Definition at line 64 of file UserManualCmd.hh.

Referenced by Do().


The documentation for this class was generated from the following files: