47 char line[1024] = {0};
48 char mime[1024] = {0};
49 char pattern[256] = {0};
51 char sicon[256] = {0};
52 char action[256] = {0};
61 mfp = fopen(filename,
"r");
63 Warning(
"TGMimeTypes",
"error opening mime type file %s", filename);
68 while (fgets(
line, 1024, mfp)) {
70 s[strlen(
line)-1] = 0;
71 while (*s ==
' ') s++;
72 if (*s ==
'#')
continue;
76 strlcpy(mime,
line, 1024);
80 if (!strncmp(s,
"pattern", 7)) {
81 if (!(s = strchr(
line,
'='))) {
82 Error(
"TGMimeTypes",
"malformed pattern line, = missing");
87 strlcpy(pattern, s, 256);
91 }
else if (!strncmp(s,
"icon", 4)) {
92 if (!(s = strchr(
line,
'='))) {
93 Error(
"TGMimeTypes",
"malformed icon line, = missing");
99 if ((s2 = strchr(s,
' '))) {
101 strlcpy(icon, s, 256);
104 strlcpy(sicon, s2, 256);
107 strlcpy(icon, s, 256);
108 strlcpy(sicon, s, 256);
113 }
else if (!strncmp(s,
"action", 6)) {
114 if (!(s = strchr(
line,
'='))) {
115 Error(
"TGMimeTypes",
"malformed action line, = missing");
120 strlcpy(action, s, 256);
127 if (strchr(pattern,
' ')) {
128 char *tmppattern = strtok(pattern,
" ");
129 while (tmppattern && (*tmppattern !=
' ')) {
130 AddType(mime, tmppattern, icon, sicon, action);
131 tmppattern = strtok(0,
" ");
134 AddType(mime, pattern, icon, sicon, action);
159 fClient(gmt.fClient),
160 fFilename(gmt.fFilename),
161 fChanged(gmt.fChanged),
187 if (!filename)
return 0;
194 while ((mime = (
TGMime *) next()))
208 if ((mime =
Find(filename))) {
230 if ((mime =
Find(filename))) {
232 return (strlen(action) > 0);
245 if ((mime =
Find(filename))) {
247 return (strlen(
type) > 0);
260 while ((
m = (
TGMime *) next())) {
261 printf(
"Type: %s\n",
m->fType.Data());
262 printf(
"Pattern: %s\n",
m->fPattern.Data());
263 if (
m->fIcon !=
m->fSIcon)
264 printf(
"Icon: %s %s\n",
m->fIcon.Data(),
m->fSIcon.Data());
266 printf(
"Icon: %s\n",
m->fIcon.Data());
267 printf(
"Action: %s\n",
m->fAction.Data());
268 printf(
"------------\n\n");
284 FILE *fp = fopen(filename.
Data(),
"wt");
287 Error(
"SaveMimes",
"can not open %s to store mime types", filename.
Data());
292 fprintf(fp,
"# %s written on %s\n\n", filename.
Data(), dt.
AsString());
297 while ((
m = (
TGMime *) next())) {
298 fprintf(fp,
"%s\n",
m->fType.Data());
299 fprintf(fp,
"pattern = %s\n",
m->fPattern.Data());
300 if (
m->fIcon !=
m->fSIcon)
301 fprintf(fp,
"icon = %s %s\n",
m->fIcon.Data(),
m->fSIcon.Data());
303 fprintf(fp,
"icon = %s\n",
m->fIcon.Data());
304 fprintf(fp,
"action = %s\n\n",
m->fAction.Data());
316 const char *sicon,
const char *action)
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
R__EXTERN TSystem * gSystem
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).
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
TGMimeTypes & operator=(const TGMimeTypes &gmt)
Assignment operator.
void Print(Option_t *option="") const
Print list of mime types.
void SaveMimes()
Save mime types in user's mime type file.
virtual ~TGMimeTypes()
Delete mime type pool.
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.
TGMimeTypes(const TGMimeTypes &gmt)
Copy constructor.
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.
~TGMime()
Delete mime object.
Mother of all ROOT objects.
TObject & operator=(const TObject &rhs)
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.
void AddFirst(TObject *obj)
Insert object at beginning of collection.
void Delete(Option_t *option="")
Remove all objects from the collection AND delete all heap based objects.
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
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.