00001 #include "ExtensionFactory.h" 00002 00003 ExtensionFactory::ExtensionFactory() 00004 { 00005 qDebug("ExtensionFactory::ExtensionFactory()"); 00006 m_pLoadList = NULL; 00007 } 00008 00009 ExtensionFactory::~ExtensionFactory() 00010 { 00011 qDebug("ExtensionFactory::~ExtensionFactory()"); 00012 } 00013 00014 ExtensionInterface* ExtensionFactory::createInstance(const QString& kind) 00015 { 00016 ExtensionInterface* ext; 00017 QString kindstr = kind.lower(); 00018 00019 if(kindstr == "switch"){ 00020 ext = new TaskSwitcher(kindstr); 00021 } else if(kindstr == "select"){ 00022 ext = new TaskSelector(kindstr); 00023 } else if(kindstr.find("launch") == 0){ 00024 ext = new KeyLauncher(kindstr); 00025 } else if(kindstr.find("menu") == 0){ 00026 ext = new MenuLauncher(kindstr); 00027 } else { 00028 return(NULL); 00029 } 00030 m_oExtList.append(ext); 00031 return(ext); 00032 } 00033 00034 ExtensionInterface* ExtensionFactory::createInstance(const QString& kind, 00035 int keycode, int keymask) 00036 { 00037 ExtensionInterface* ext; 00038 QString kindstr = kind.lower(); 00039 00040 ext = loadInstance(kindstr, keycode, keymask); 00041 if(ext != NULL){ 00042 return(ext); 00043 } 00044 00045 if(kindstr == "switch"){ 00046 ext = new TaskSwitcher(kindstr); 00047 } else if(kindstr == "select"){ 00048 ext = new TaskSelector(kindstr); 00049 } else if(kindstr.find("launch") == 0){ 00050 ext = new KeyLauncher(kindstr); 00051 } else if(kindstr.find("menu") == 0){ 00052 ext = new MenuLauncher(kindstr); 00053 } else { 00054 return(NULL); 00055 } 00056 ext->setKeycode(keycode); 00057 ext->setKeymask(keymask); 00058 00059 m_oExtList.append(ext); 00060 return(ext); 00061 } 00062 00063 ExtensionInterface* ExtensionFactory::loadInstance(const QString& kindstr, 00064 int keycode, int keymask) 00065 { 00066 if(m_pLoadList == NULL){ 00067 return(NULL); 00068 } 00069 00070 for(ExtensionList::Iterator it=m_pLoadList->begin(); 00071 it!=m_pLoadList->end(); ++it){ 00072 if((*it)->kind() == kindstr 00073 && (*it)->getKeycode() == keycode 00074 && (*it)->getKeymask() == keymask){ 00075 m_oExtList.append(*it); 00076 return(*it); 00077 } 00078 } 00079 return(NULL); 00080 } 00081 00082 void ExtensionFactory::clear() 00083 { 00084 for(ExtensionList::Iterator it=m_oExtList.begin(); 00085 it!=m_oExtList.end(); ++it){ 00086 delete *it; 00087 } 00088 m_oExtList.clear(); 00089 } 00090 00091 void ExtensionFactory::reset() 00092 { 00093 m_pLoadList = new ExtensionList(m_oExtList); 00094 m_oExtList.clear(); 00095 } 00096 00097 void ExtensionFactory::sweep() 00098 { 00099 if(m_pLoadList == NULL){ 00100 return; 00101 } 00102 for(ExtensionList::Iterator it=m_pLoadList->begin(); 00103 it!=m_pLoadList->end(); ++it){ 00104 if(m_oExtList.contains(*it) == false){ 00105 delete *it; 00106 } 00107 } 00108 delete m_pLoadList; 00109 m_pLoadList = NULL; 00110 }
1.4.2