Merge lp:~xzcvczx/kicad/gestfich-cleanup into lp:kicad/product

Proposed by xzcvczx
Status: Merged
Merged at revision: 6419
Proposed branch: lp:~xzcvczx/kicad/gestfich-cleanup
Merge into: lp:kicad/product
Diff against target: 153 lines (+19/-77)
1 file modified
common/gestfich.cpp (+19/-77)
To merge this branch: bzr merge lp:~xzcvczx/kicad/gestfich-cleanup
Reviewer Review Type Date Requested Status
Nick Østergaard (community) Approve
Wayne Stambaugh Approve
Review via email: mp+281447@code.launchpad.net

Description of the change

Cleaned up an old work-around from OpenPDF
Made ExecuteFile quote the command name on osx due to it not working if the text editor had a space in the name

To post a comment you must log in.
Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

1) wxMimeTypeManager::GetFileTypeFromExtenstion() can return NULL. Your change ignores the return value and calls GetOpenCommand() without testing for NULL. It may not segfault depending on the behavior of GetOpenCommand() but you should still test for NULL and warn the use that the PDF mime type is not assigned.

2) I'm not sure removing all of the default platform specific PDF viewer applications is a good idea. If users do not have the default mime type set for PDF files (it can happen), my guess it that they would expect a reasonable default action to occur. We should get some user input on this before we remove it.

3) There are some coding policy violations. The "if (" statements should be "if( ".

review: Needs Fixing
Revision history for this message
xzcvczx (xzcvczx) wrote :

> 1) wxMimeTypeManager::GetFileTypeFromExtenstion() can return NULL. Your
> change ignores the return value and calls GetOpenCommand() without testing for
> NULL. It may not segfault depending on the behavior of GetOpenCommand() but
> you should still test for NULL and warn the use that the PDF mime type is not
> assigned.
>
> 2) I'm not sure removing all of the default platform specific PDF viewer
> applications is a good idea. If users do not have the default mime type set
> for PDF files (it can happen), my guess it that they would expect a reasonable
> default action to occur. We should get some user input on this before we
> remove it.
>
> 3) There are some coding policy violations. The "if (" statements should be
> "if( ".

i had meant to do the if NULL but got distracted and apparently forgot

With #2 would it not be better to just provide a dialog box saying that no handler was found for pdf files and provide the option to set one?

woops hadn't noticed #3 will fix that as well

lp:~xzcvczx/kicad/gestfich-cleanup updated
6412. By xzcvczx

Ensure filetype is not null before using open command, Fixed if statements to follow coding guidelines

6413. By xzcvczx

Reorder includes to a more logical order

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

On 1/1/2016 2:00 AM, Simon Wells wrote:
>> 1) wxMimeTypeManager::GetFileTypeFromExtenstion() can return NULL. Your
>> change ignores the return value and calls GetOpenCommand() without testing for
>> NULL. It may not segfault depending on the behavior of GetOpenCommand() but
>> you should still test for NULL and warn the use that the PDF mime type is not
>> assigned.
>>
>> 2) I'm not sure removing all of the default platform specific PDF viewer
>> applications is a good idea. If users do not have the default mime type set
>> for PDF files (it can happen), my guess it that they would expect a reasonable
>> default action to occur. We should get some user input on this before we
>> remove it.
>>
>> 3) There are some coding policy violations. The "if (" statements should be
>> "if( ".
>
> i had meant to do the if NULL but got distracted and apparently forgot
>
> With #2 would it not be better to just provide a dialog box saying that no handler was found for pdf files and provide the option to set one?

This is fine as long as no one else objects. The only issue may be
users who don't have their PDF mime type configured. They may be
unhappy when their PDF viewer no long works.

>
> woops hadn't noticed #3 will fix that as well
>

Let me know when you've made these changes.

Thanks,

Wayne

Revision history for this message
Chris Pavlina (pavlina-chris) wrote :

If users have no PDF viewer configured, why should it work? It won't work anywhere else either. Their whole system will tell them there's no configured viewer and yell at them, not just KiCad.

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

Yes, but this change removes the list of "reasonable" default platform
specific PDF applications which KiCad checks for when the mime type is
not defined so some users may be affected. I agree that only the mime
type check should be used but we will be breaking the current behavior
which almost always results in user issues.

On 1/4/2016 11:10 AM, Chris Pavlina wrote:
> If users have no PDF viewer configured, why should it work? It won't work anywhere else either. Their whole system will tell them there's no configured viewer and yell at them, not just KiCad.
>

Revision history for this message
Chris Pavlina (pavlina-chris) wrote :

Every change results in user issues. Seriously, I've been yelled at by _somebody_ for everything I've done and many things other people have. We really shouldn't be performing the function of the operating system by handling file associations.

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

The merge request looks fine with the latest changes.

review: Approve
Revision history for this message
Nick Østergaard (nickoe) wrote :

I think it makes sense to remove those "magic" defaults. I just tested this on archlinux and it opens evince, which is my system default.

I wonder why a space was added to the error message for the if( ProcessExecute( command ) ).

lp:~xzcvczx/kicad/gestfich-cleanup updated
6414. By xzcvczx

Removed the space in the error message after the new line

Revision history for this message
Nick Østergaard (nickoe) :
review: Approve
Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

Patch committed in r6419. Thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'common/gestfich.cpp'
2--- common/gestfich.cpp 2015-09-25 19:38:09 +0000
3+++ common/gestfich.cpp 2016-01-04 17:13:05 +0000
4@@ -28,33 +28,26 @@
5 * @brief Functions for file management
6 */
7
8+#include <wx/mimetype.h>
9+#include <wx/filename.h>
10+#include <wx/dir.h>
11+
12 // For compilers that support precompilation, includes "wx.h".
13 #include <fctsys.h>
14 #include <pgm_base.h>
15 #include <confirm.h>
16-
17 #include <common.h>
18 #include <macros.h>
19+
20 #include <gestfich.h>
21
22-#include <wx/mimetype.h>
23-#include <wx/filename.h>
24-#include <wx/dir.h>
25-
26-
27 void AddDelimiterString( wxString& string )
28 {
29- wxString text;
30-
31 if( !string.StartsWith( wxT( "\"" ) ) )
32- text = wxT( "\"" );
33-
34- text += string;
35-
36- if( (text.Last() != '"' ) || (text.length() <= 1) )
37- text += wxT( "\"" );
38-
39- string = text;
40+ {
41+ string.Prepend ( wxT( "\"" ) );
42+ string.Append ( wxT( "\"" ) );
43+ }
44 }
45
46
47@@ -227,6 +220,8 @@
48 #ifdef __WXMAC__
49 else
50 {
51+ AddDelimiterString( fullFileName );
52+
53 if( !param.IsEmpty() )
54 fullFileName += wxT( " " ) + param;
55
56@@ -351,8 +346,6 @@
57 {
58 wxString command;
59 wxString filename = file;
60- wxString type;
61- bool success = false;
62
63 Pgm().ReadPdfBrowserInfos();
64
65@@ -363,71 +356,21 @@
66 }
67 else
68 {
69- wxFileType* filetype = NULL;
70- wxFileType::MessageParameters params( filename, type );
71- filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) );
72+ wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) );
73
74 if( filetype )
75- success = filetype->GetOpenCommand( &command, params );
76+ command = filetype->GetOpenCommand( filename );
77
78 delete filetype;
79-
80-#ifndef __WINDOWS__
81-
82- // Bug ? under linux wxWidgets returns acroread as PDF viewer, even if
83- // it does not exist.
84- if( command.StartsWith( wxT( "acroread" ) ) ) // Workaround
85- success = false;
86-#endif
87-
88- if( success && !command.IsEmpty() )
89- {
90- success = ProcessExecute( command );
91-
92- if( success )
93- return success;
94- }
95-
96- success = false;
97- command.clear();
98-
99- if( !success )
100- {
101-#if !defined(__WINDOWS__)
102- AddDelimiterString( filename );
103-
104- // here is a list of PDF viewers candidates
105- static const wxChar* tries[] =
106- {
107- wxT( "/usr/bin/evince" ),
108- wxT( "/usr/bin/okular" ),
109- wxT( "/usr/bin/gpdf" ),
110- wxT( "/usr/bin/konqueror" ),
111- wxT( "/usr/bin/kpdf" ),
112- wxT( "/usr/bin/xpdf" ),
113- wxT( "/usr/bin/open" ), // BSD and OSX file & dir opener
114- wxT( "/usr/bin/xdg-open" ), // Freedesktop file & dir opener
115- };
116-
117- for( unsigned ii = 0; ii<DIM(tries); ii++ )
118- {
119- if( wxFileExists( tries[ii] ) )
120- {
121- command = tries[ii];
122- command += wxT( ' ' );
123- command += filename;
124- break;
125- }
126- }
127-#endif
128- }
129 }
130
131 if( !command.IsEmpty() )
132 {
133- success = ProcessExecute( command );
134-
135- if( !success )
136+ if( ProcessExecute( command ) )
137+ {
138+ return true;
139+ }
140+ else
141 {
142 wxString msg;
143 msg.Printf( _( "Problem while running the PDF viewer\nCommand is '%s'" ),
144@@ -440,10 +383,9 @@
145 wxString msg;
146 msg.Printf( _( "Unable to find a PDF viewer for <%s>" ), GetChars( filename ) );
147 DisplayError( NULL, msg );
148- success = false;
149 }
150
151- return success;
152+ return false;
153 }
154
155