|
MythTV
0.26-pre
|
00001 #include "recordingprofile.h" 00002 #include "videosource.h" 00003 #include "profilegroup.h" 00004 #include "mythdb.h" 00005 #include "mythuihelper.h" 00006 #include "cardutil.h" 00007 00008 QString ProfileGroupStorage::GetWhereClause(MSqlBindings &bindings) const 00009 { 00010 QString idTag(":WHEREID"); 00011 QString query("id = " + idTag); 00012 00013 bindings.insert(idTag, m_parent.getProfileNum()); 00014 00015 return query; 00016 } 00017 00018 QString ProfileGroupStorage::GetSetClause(MSqlBindings &bindings) const 00019 { 00020 QString idTag(":SETID"); 00021 QString colTag(":SET" + GetColumnName().toUpper()); 00022 00023 QString query("id = " + idTag + ", " + 00024 GetColumnName() + " = " + colTag); 00025 00026 bindings.insert(idTag, m_parent.getProfileNum()); 00027 bindings.insert(colTag, user->GetDBValue()); 00028 00029 return query; 00030 } 00031 00032 void ProfileGroup::HostName::fillSelections() 00033 { 00034 QStringList hostnames; 00035 ProfileGroup::getHostNames(&hostnames); 00036 for(QStringList::Iterator it = hostnames.begin(); 00037 it != hostnames.end(); it++) 00038 this->addSelection(*it); 00039 } 00040 00041 ProfileGroup::ProfileGroup() 00042 { 00043 // This must be first because it is needed to load/save the other settings 00044 addChild(id = new ID()); 00045 addChild(is_default = new Is_default(*this)); 00046 00047 ConfigurationGroup* profile = new VerticalConfigurationGroup(false); 00048 profile->setLabel(QObject::tr("ProfileGroup")); 00049 profile->addChild(name = new Name(*this)); 00050 CardInfo *cardInfo = new CardInfo(*this); 00051 profile->addChild(cardInfo); 00052 CardType::fillSelections(cardInfo); 00053 host = new HostName(*this); 00054 profile->addChild(host); 00055 host->fillSelections(); 00056 addChild(profile); 00057 }; 00058 00059 void ProfileGroup::loadByID(int profileId) { 00060 id->setValue(profileId); 00061 Load(); 00062 } 00063 00064 void ProfileGroup::fillSelections(SelectSetting* setting) 00065 { 00066 QStringList cardtypes = CardUtil::GetCardTypes(); 00067 QString tid = QString::null; 00068 00069 MSqlQuery result(MSqlQuery::InitCon()); 00070 result.prepare( 00071 "SELECT name, id, hostname, is_default, cardtype " 00072 "FROM profilegroups"); 00073 00074 if (!result.exec()) 00075 { 00076 MythDB::DBError("ProfileGroup::fillSelections", result); 00077 return; 00078 } 00079 00080 while (result.next()) 00081 { 00082 QString name = result.value(0).toString(); 00083 QString id = result.value(1).toString(); 00084 QString hostname = result.value(2).toString(); 00085 bool is_default = (bool) result.value(3).toInt(); 00086 QString cardtype = result.value(4).toString(); 00087 00088 // Only show default profiles that match installed cards 00089 bool have_cardtype = cardtypes.contains(cardtype); 00090 if (is_default && (cardtype == "TRANSCODE") && !have_cardtype) 00091 { 00092 tid = id; 00093 } 00094 else if (have_cardtype) 00095 { 00096 if (!hostname.isEmpty()) 00097 name += QString(" (%1)").arg(result.value(2).toString()); 00098 00099 setting->addSelection(name, id); 00100 } 00101 } 00102 00103 if (!tid.isEmpty()) 00104 setting->addSelection(QObject::tr("Transcoders"), tid); 00105 } 00106 00107 QString ProfileGroup::getName(int group) 00108 { 00109 MSqlQuery result(MSqlQuery::InitCon()); 00110 QString querystr = QString("SELECT name from profilegroups WHERE id = %1") 00111 .arg(group); 00112 result.prepare(querystr); 00113 00114 if (result.exec() && result.next()) 00115 { 00116 return result.value(0).toString(); 00117 } 00118 00119 return NULL; 00120 } 00121 00122 bool ProfileGroup::allowedGroupName(void) 00123 { 00124 MSqlQuery result(MSqlQuery::InitCon()); 00125 QString querystr = QString("SELECT DISTINCT id FROM profilegroups WHERE " 00126 "name = '%1' AND hostname = '%2';") 00127 .arg(getName()).arg(host->getValue()); 00128 result.prepare(querystr); 00129 00130 if (result.exec() && result.next()) 00131 return false; 00132 return true; 00133 } 00134 00135 void ProfileGroup::getHostNames(QStringList *hostnames) 00136 { 00137 hostnames->clear(); 00138 00139 MSqlQuery result(MSqlQuery::InitCon()); 00140 00141 result.prepare("SELECT DISTINCT hostname from capturecard"); 00142 00143 if (result.exec() && result.isActive() && result.size() > 0) 00144 { 00145 while (result.next()) 00146 hostnames->append(result.value(0).toString()); 00147 } 00148 } 00149 00150 void ProfileGroupEditor::open(int id) { 00151 00152 ProfileGroup* profilegroup = new ProfileGroup(); 00153 00154 bool isdefault = false; 00155 bool show_profiles = true; 00156 bool newgroup = false; 00157 int profileID; 00158 QString pgName; 00159 00160 if (id != 0) 00161 { 00162 profilegroup->loadByID(id); 00163 pgName = profilegroup->getName(); 00164 if (profilegroup->isDefault()) 00165 isdefault = true; 00166 } 00167 else 00168 { 00169 pgName = QString(QObject::tr("New Profile Group Name")); 00170 profilegroup->setName(pgName); 00171 newgroup = true; 00172 } 00173 00174 if (! isdefault) 00175 { 00176 if (profilegroup->exec(false) == QDialog::Accepted && 00177 profilegroup->allowedGroupName()) 00178 { 00179 profilegroup->Save(); 00180 profileID = profilegroup->getProfileNum(); 00181 vector<int> found; 00182 00183 MSqlQuery result(MSqlQuery::InitCon()); 00184 QString querystr = QString("SELECT name FROM recordingprofiles WHERE " 00185 "profilegroup = %1").arg(profileID); 00186 result.prepare(querystr); 00187 00188 if (result.exec() && result.isActive() && result.size() > 0) 00189 { 00190 while (result.next()) 00191 { 00192 for (int i = 0; availProfiles[i] != ""; i++) 00193 if (result.value(0).toString() == availProfiles[i]) 00194 found.push_back(i); 00195 } 00196 } 00197 00198 for(int i = 0; availProfiles[i] != ""; i++) 00199 { 00200 bool skip = false; 00201 00202 for (vector<int>::iterator j = found.begin(); 00203 j != found.end(); ++j) 00204 { 00205 if (i == *j) 00206 skip = true; 00207 } 00208 if (! skip) 00209 { 00210 result.prepare("INSERT INTO recordingprofiles " 00211 "(name, profilegroup) VALUES (:NAME, :PROFID);"); 00212 result.bindValue(":NAME", availProfiles[i]); 00213 result.bindValue(":PROFID", profileID); 00214 if (!result.exec()) 00215 MythDB::DBError("ProfileGroup::getHostNames", result); 00216 } 00217 } 00218 } 00219 else if (newgroup) 00220 show_profiles = false; 00221 } 00222 00223 if (show_profiles) 00224 { 00225 pgName = profilegroup->getName(); 00226 profileID = profilegroup->getProfileNum(); 00227 RecordingProfileEditor editor(profileID, pgName); 00228 editor.exec(); 00229 } 00230 delete profilegroup; 00231 }; 00232 00233 void ProfileGroupEditor::Load(void) 00234 { 00235 listbox->clearSelections(); 00236 ProfileGroup::fillSelections(listbox); 00237 listbox->addSelection(QObject::tr("(Create new profile group)"), "0"); 00238 } 00239 00240 DialogCode ProfileGroupEditor::exec(void) 00241 { 00242 DialogCode ret = kDialogCodeAccepted; 00243 redraw = true; 00244 00245 while ((QDialog::Accepted == ret) || redraw) 00246 { 00247 redraw = false; 00248 00249 Load(); 00250 00251 dialog = new ConfigurationDialogWidget(GetMythMainWindow(), 00252 "ProfileGroupEditor"); 00253 00254 connect(dialog, SIGNAL(menuButtonPressed()), this, SLOT(callDelete())); 00255 00256 int width = 0, height = 0; 00257 float wmult = 0.0f, hmult = 0.0f; 00258 GetMythUI()->GetScreenSettings(width, wmult, height, hmult); 00259 00260 QVBoxLayout *layout = new QVBoxLayout(dialog); 00261 layout->setMargin((int)(20 * hmult)); 00262 layout->addWidget(listbox->configWidget(NULL, dialog)); 00263 00264 dialog->Show(); 00265 00266 ret = dialog->exec(); 00267 00268 dialog->deleteLater(); 00269 dialog = NULL; 00270 00271 if (ret == QDialog::Accepted) 00272 open(listbox->getValue().toInt()); 00273 } 00274 00275 return kDialogCodeRejected; 00276 } 00277 00278 void ProfileGroupEditor::callDelete(void) 00279 { 00280 int id = listbox->getValue().toInt(); 00281 00282 MSqlQuery result(MSqlQuery::InitCon()); 00283 QString querystr = QString("SELECT id FROM profilegroups WHERE " 00284 "id = %1 AND is_default = 0;").arg(id); 00285 result.prepare(querystr); 00286 00287 if (result.exec() && result.next()) 00288 { 00289 QString message = QObject::tr("Delete profile group:") + 00290 QString("\n'%1'?").arg(ProfileGroup::getName(id)); 00291 00292 DialogCode value = MythPopupBox::Show2ButtonPopup( 00293 GetMythMainWindow(), 00294 "", message, 00295 QObject::tr("Yes, delete group"), 00296 QObject::tr("No, Don't delete group"), kDialogCodeButton1); 00297 00298 if (kDialogCodeButton0 == value) 00299 { 00300 querystr = QString("DELETE codecparams FROM codecparams, " 00301 "recordingprofiles WHERE " 00302 "codecparams.profile = recordingprofiles.id " 00303 "AND recordingprofiles.profilegroup = %1").arg(id); 00304 result.prepare(querystr); 00305 if (!result.exec()) 00306 MythDB::DBError("ProfileGroupEditor::callDelete -- " 00307 "delete codecparams", result); 00308 00309 querystr = QString("DELETE FROM recordingprofiles WHERE " 00310 "profilegroup = %1").arg(id); 00311 result.prepare(querystr); 00312 if (!result.exec()) 00313 MythDB::DBError("ProfileGroupEditor::callDelete -- " 00314 "delete recordingprofiles", result); 00315 00316 querystr = QString("DELETE FROM profilegroups WHERE id = %1;").arg(id); 00317 result.prepare(querystr); 00318 if (!result.exec()) 00319 MythDB::DBError("ProfileGroupEditor::callDelete -- " 00320 "delete profilegroups", result); 00321 00322 redraw = true; 00323 00324 if (dialog) 00325 dialog->done(QDialog::Rejected); 00326 } 00327 } 00328 00329 } 00330
1.7.6.1