46 char line[1024] = {0};
47 char mime[1024] = {0};
48 char pattern[256] = {0};
50 char sicon[256] = {0};
51 char action[256] = {0};
60 mfp = fopen(filename,
"r");
62 Warning(
"TGMimeTypes",
"error opening mime type file %s", filename);
67 while (fgets(
line, 1024, mfp)) {
69 s[strlen(
line)-1] = 0;
70 while (*s ==
' ') s++;
71 if (*s ==
'#')
continue;
75 strlcpy(mime,
line, 1024);
79 if (!strncmp(s,
"pattern", 7)) {
80 if (!(s = strchr(
line,
'='))) {
81 Error(
"TGMimeTypes",
"malformed pattern line, = missing");
86 strlcpy(pattern, s, 256);
90 }
else if (!strncmp(s,
"icon", 4)) {
91 if (!(s = strchr(
line,
'='))) {
92 Error(
"TGMimeTypes",
"malformed icon line, = missing");
98 if ((s2 = strchr(s,
' '))) {
100 strlcpy(icon, s, 256);
103 strlcpy(sicon, s2, 256);
106 strlcpy(icon, s, 256);
107 strlcpy(sicon, s, 256);
112 }
else if (!strncmp(s,
"action", 6)) {
113 if (!(s = strchr(
line,
'='))) {
114 Error(
"TGMimeTypes",
"malformed action line, = missing");
119 strlcpy(action, s, 256);
126 if (strchr(pattern,
' ')) {
127 char *tmppattern = strtok(pattern,
" ");
128 while (tmppattern && (*tmppattern !=
' ')) {
129 AddType(mime, tmppattern, icon, sicon, action);
130 tmppattern = strtok(0,
" ");
133 AddType(mime, pattern, icon, sicon, action);
186 if (!filename)
return 0;
193 while ((mime = (
TGMime *) next()))
207 if ((mime =
Find(filename))) {
229 if ((mime =
Find(filename))) {
231 return (strlen(action) > 0);
243 memset(type, 0, strlen(type));
244 if ((mime =
Find(filename))) {
246 return (strlen(type) > 0);
259 while ((
m = (
TGMime *) next())) {
260 printf(
"Type: %s\n",
m->fType.Data());
261 printf(
"Pattern: %s\n",
m->fPattern.Data());
262 if (
m->fIcon !=
m->fSIcon)
263 printf(
"Icon: %s %s\n",
m->fIcon.Data(),
m->fSIcon.Data());
265 printf(
"Icon: %s\n",
m->fIcon.Data());
266 printf(
"Action: %s\n",
m->fAction.Data());
267 printf(
"------------\n\n");
278 filename.
Form(
"%s\\.root.mimes",
gSystem->HomeDirectory());
280 filename.
Form(
"%s/.root.mimes",
gSystem->HomeDirectory());
283 FILE *fp = fopen(filename.
Data(),
"wt");
286 Error(
"SaveMimes",
"can not open %s to store mime types", filename.
Data());
291 fprintf(fp,
"# %s written on %s\n\n", filename.
Data(), dt.
AsString());
296 while ((
m = (
TGMime *) next())) {
297 fprintf(fp,
"%s\n",
m->fType.Data());
298 fprintf(fp,
"pattern = %s\n",
m->fPattern.Data());
299 if (
m->fIcon !=
m->fSIcon)
300 fprintf(fp,
"icon = %s %s\n",
m->fIcon.Data(),
m->fSIcon.Data());
302 fprintf(fp,
"icon = %s\n",
m->fIcon.Data());
303 fprintf(fp,
"action = %s\n\n",
m->fAction.Data());
315 const char *sicon,
const char *action)
327 fList->AddFirst(mime);
bool Bool_t
Boolean (0=false, 1=true) (bool).
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
const char Option_t
Option string (const char).
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
const char * AsString() const
Return the date & time as a string (ctime() format).
TGMimeTypes & operator=(const TGMimeTypes &gmt)
Assignment operator.
Bool_t fChanged
true if file has changed
void SaveMimes()
Save mime types in user's mime type file.
TGMime * Find(const char *filename)
Given a filename find the matching mime type object.
void AddType(const char *type, const char *pat, const char *icon, const char *sicon, const char *action)
Add a mime type to the list of mime types.
TOrdCollection * fList
list of mime types
TGMimeTypes(const TGMimeTypes &gmt)
Copy constructor.
~TGMimeTypes() override
Delete mime type pool.
TGClient * fClient
client to which mime types belong (display server)
void Print(Option_t *option="") const override
Print list of mime types.
const TGPicture * GetIcon(const char *filename, Bool_t small_icon)
Return icon belonging to mime type of filename.
Bool_t GetAction(const char *filename, char *action)
Return in action the mime action string belonging to filename.
Bool_t GetType(const char *filename, char *type)
Return in type the mime type belonging to filename.
TString fFilename
file name of mime type file
TGMime is internally used by TGMimeTypes.
TString fPattern
filename pattern
TRegexp * fReg
pattern regular expression
TString fIcon
associated icon (32x32)
TString fAction
associated action
~TGMime() override
Delete mime object.
TString fSIcon
associated small icon (16x16)
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
TObject & operator=(const TObject &rhs) noexcept
TObject assignment operator.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TObject()
TObject constructor.
Regular expression class.
const char * Data() const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const