llmimetypes.cpp

Go to the documentation of this file.
00001 
00033 #include "llviewerprecompiledheaders.h"
00034 
00035 #include "llmimetypes.h"
00036 
00037 #include "lluictrlfactory.h"
00038 
00039 LLMIMETypes::mime_info_map_t LLMIMETypes::sMap;
00040 LLMIMETypes::mime_widget_set_map_t LLMIMETypes::sWidgetMap;
00041 
00042 LLString sDefaultLabel;
00043         // Returned when we don't know what to do with the mime type
00044 LLString sDefaultWidgetType;
00045         // Returned when we don't know what widget set to use
00046 LLString sDefaultImpl;
00047         // Returned when we don't know what impl to use
00048 
00050 
00051 // static
00052 bool LLMIMETypes::parseMIMETypes(const LLString& xml_filename)
00053 {
00054         LLXMLNodePtr root;
00055         bool success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root);
00056         if ( ! success || root.isNull() || ! root->hasName( "mimetypes" ) )
00057         {
00058                 llwarns << "Unable to read MIME type file: "
00059                         << xml_filename << llendl;
00060                 return false;
00061         }
00062 
00063         for (LLXMLNode* node = root->getFirstChild();
00064                  node != NULL;
00065                  node = node->getNextSibling())
00066         {
00067                 if (node->hasName("defaultlabel"))
00068                 {
00069                         sDefaultLabel = node->getTextContents();
00070                 }
00071                 else if (node->hasName("defaultwidget"))
00072                 {
00073                         sDefaultWidgetType = node->getTextContents();
00074                 }
00075                 else if (node->hasName("defaultimpl"))
00076                 {
00077                         sDefaultImpl = node->getTextContents();
00078                 }
00079                 else if (node->hasName("mimetype") || node->hasName("scheme"))
00080                 {
00081                         LLString mime_type;
00082                         node->getAttributeString("name", mime_type);
00083                         LLMIMEInfo info;
00084                         for (LLXMLNode* child = node->getFirstChild();
00085                                  child != NULL;
00086                                  child = child->getNextSibling())
00087                         {
00088                                 if (child->hasName("label"))
00089                                 {
00090                                         info.mLabel = child->getTextContents();
00091                                 }
00092                                 else if (child->hasName("widgettype"))
00093                                 {
00094                                         info.mWidgetType = child->getTextContents();
00095                                 }
00096                                 else if (child->hasName("impl"))
00097                                 {
00098                                         info.mImpl = child->getTextContents();
00099                                 }
00100                         }
00101                         sMap[mime_type] = info;
00102                 }
00103                 else if (node->hasName("widgetset"))
00104                 {
00105                         LLString set_name;
00106                         node->getAttributeString("name", set_name);
00107                         LLMIMEWidgetSet info;
00108                         for (LLXMLNode* child = node->getFirstChild();
00109                                 child != NULL;
00110                                 child = child->getNextSibling())
00111                         {
00112                                 if (child->hasName("label"))
00113                                 {
00114                                         info.mLabel = child->getTextContents();
00115                                 }
00116                                 if (child->hasName("icon"))
00117                                 {
00118                                         info.mIcon = child->getTextContents();
00119                                 }
00120                                 if (child->hasName("default_type"))
00121                                 {
00122                                         info.mDefaultMimeType = child->getTextContents();
00123                                 }
00124                                 if (child->hasName("tooltip"))
00125                                 {
00126                                         info.mToolTip = child->getTextContents();
00127                                 }
00128                                 if (child->hasName("playtip"))
00129                                 {
00130                                         info.mPlayTip = child->getTextContents();
00131                                 }
00132                                 if (child->hasName("allow_resize"))
00133                                 {
00134                                         BOOL allow_resize = FALSE;
00135                                         child->getBoolValue( 1, &allow_resize );
00136                                         info.mAllowResize = (bool)allow_resize;
00137                                 }
00138                                 if (child->hasName("allow_looping"))
00139                                 {
00140                                         BOOL allow_looping = FALSE;
00141                                         child->getBoolValue( 1, &allow_looping );
00142                                         info.mAllowLooping = (bool)allow_looping;
00143                                 }
00144                         }
00145                         sWidgetMap[set_name] = info;
00146                 }
00147         }
00148         return true;
00149 }
00150 
00151 // static
00152 LLString LLMIMETypes::translate(const LLString& mime_type)
00153 {
00154         mime_info_map_t::const_iterator it = sMap.find(mime_type);
00155         if (it != sMap.end())
00156         {
00157                 return it->second.mLabel;
00158         }
00159         else
00160         {
00161                 return sDefaultLabel;
00162         }
00163 }
00164 
00165 // static
00166 LLString LLMIMETypes::widgetType(const LLString& mime_type)
00167 {
00168         mime_info_map_t::const_iterator it = sMap.find(mime_type);
00169         if (it != sMap.end())
00170         {
00171                 return it->second.mWidgetType;
00172         }
00173         else
00174         {
00175                 return sDefaultWidgetType;
00176         }
00177 }
00178 
00179 // static
00180 LLString LLMIMETypes::implType(const LLString& mime_type)
00181 {
00182         mime_info_map_t::const_iterator it = sMap.find(mime_type);
00183         if (it != sMap.end())
00184         {
00185                 return it->second.mImpl;
00186         }
00187         else
00188         {
00189                 return sDefaultImpl;
00190         }
00191 }
00192 
00193 // static
00194 LLString LLMIMETypes::findIcon(const LLString& mime_type)
00195 {
00196         LLString icon = "";
00197         LLString widget_type = LLMIMETypes::widgetType(mime_type);
00198         mime_widget_set_map_t::iterator it = sWidgetMap.find(widget_type);
00199         if(it != sWidgetMap.end())
00200         {
00201                 icon = it->second.mIcon;
00202         }
00203         return icon;
00204 }
00205 
00206 // static
00207 LLString LLMIMETypes::findDefaultMimeType(const LLString& widget_type)
00208 {
00209         LLString mime_type = "none/none";
00210         mime_widget_set_map_t::iterator it = sWidgetMap.find(widget_type);
00211         if(it != sWidgetMap.end())
00212         {
00213                 mime_type = it->second.mDefaultMimeType;
00214         }
00215         return mime_type;
00216 }
00217 
00218 // static
00219 LLString LLMIMETypes::findToolTip(const LLString& mime_type)
00220 {
00221         LLString tool_tip = "";
00222         LLString widget_type = LLMIMETypes::widgetType(mime_type);
00223         mime_widget_set_map_t::iterator it = sWidgetMap.find(widget_type);
00224         if(it != sWidgetMap.end())
00225         {
00226                 tool_tip = it->second.mToolTip;
00227         }
00228         return tool_tip;
00229 }
00230 
00231 // static
00232 LLString LLMIMETypes::findPlayTip(const LLString& mime_type)
00233 {
00234         LLString play_tip = "";
00235         LLString widget_type = LLMIMETypes::widgetType(mime_type);
00236         mime_widget_set_map_t::iterator it = sWidgetMap.find(widget_type);
00237         if(it != sWidgetMap.end())
00238         {
00239                 play_tip = it->second.mPlayTip;
00240         }
00241         return play_tip;
00242 }
00243 
00244 // static
00245 bool LLMIMETypes::findAllowResize(const LLString& mime_type)
00246 {
00247         bool allow_resize = false;
00248         LLString widget_type = LLMIMETypes::widgetType(mime_type);
00249         mime_widget_set_map_t::iterator it = sWidgetMap.find(widget_type);
00250         if(it != sWidgetMap.end())
00251         {
00252                 allow_resize = it->second.mAllowResize;
00253         }
00254         return allow_resize;
00255 }
00256 
00257 // static
00258 bool LLMIMETypes::findAllowLooping(const LLString& mime_type)
00259 {
00260         bool allow_looping = false;
00261         LLString widget_type = LLMIMETypes::widgetType(mime_type);
00262         mime_widget_set_map_t::iterator it = sWidgetMap.find(widget_type);
00263         if(it != sWidgetMap.end())
00264         {
00265                 allow_looping = it->second.mAllowLooping;
00266         }
00267         return allow_looping;
00268 }

Generated on Fri May 16 08:33:47 2008 for SecondLife by  doxygen 1.5.5