Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Move INSTALL, LICENSE, README, THANKS and TODO into root directory
[xestiaab/.git] / source / common / mime.cpp
1 // mime.cpp - MIME subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include <wx/wx.h>
21 wxString GetMIME(wxString FilenameInc){
22     
23         wxString MIMEResult;
24     
25         // Check if file exists first before doing anything with it.
26     
27         if (!wxFileExists(FilenameInc)){
28         
29             // File doesn't exist so return.
30         
31             wxMessageBox(_("The file with the filename given doesn't exist."), _("Error opening picture/audio file"), wxICON_ERROR);
32             return wxEmptyString;
33         
34         }
35     
36 #if defined(__WIN32__)
37     
38         // TODO: Sort out Win32.
39     
40 #else
41     
42 #include <stdio.h>
43     
44         FILE *MIMEIn;
45     
46         char MIMEData[512];
47     
48         // Build Command Line.
49     
50         wxString FilenameIncEscaped = FilenameInc;
51         FilenameIncEscaped.Replace(wxT(" "), wxT("\\ "));
52         wxString FileCommandLine;
53     
54         FileCommandLine.Append("file -b --mime-type ");
55         FileCommandLine.Append(FilenameIncEscaped);
56     
57         if (!(MIMEIn = popen(FileCommandLine.mb_str(), "r"))){
58         
59             wxMessageBox(_("The file with the filename given doesn't exist."), _("Error opening picture/audio file"), wxICON_ERROR);
60             return wxEmptyString;
61         
62         }
63     
64         while(fgets(MIMEData, sizeof(MIMEData), MIMEIn) != NULL){
65             MIMEResult.Append(wxString::FromUTF8(MIMEData));
66         }
67         pclose(MIMEIn);
68     
69         MIMEResult.Trim();
70     
71 #endif
72     
73         return MIMEResult;
74     
75 }
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy