PageRenderTime 336ms CodeModel.GetById 48ms RepoModel.GetById 7ms app.codeStats 0ms

/acetoneiso_2.3/acetoneiso/sources/global_functions.h

#
C Header | 420 lines | 303 code | 66 blank | 51 comment | 18 complexity | cc6c8f8db6b93d4f25eaf54ecad96c78 MD5 | raw file
Possible License(s): GPL-3.0
  1. //This file is part of AcetoneISO. Copyright 2006,2007,2008,2009 Fabrizio Di Marco and Marco Di Antonio (acetoneiso@gmail.com)
  2. //
  3. // AcetoneISO is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // AcetoneISO is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with AcetoneISO. If not, see <http://www.gnu.org/licenses/>.
  15. //donazione
  16. void acetoneiso::paypal() {
  17. QUrl url("http://www.acetoneteam.org/donate.html");
  18. QDesktopServices::openUrl(url);
  19. }
  20. //funzione che si occupa di vedere se c'e' una virtual drive libera, se c'e' chiama il mount passandogli il percorso dell immagine e del virtual drive libero
  21. void acetoneiso::global_functions_mount(QString immagine_con_percorso) {
  22. QFile fus;
  23. fus.setFileName("/usr/bin/fuseiso");
  24. if (!fus.exists()) {
  25. QMessageBox::critical(this, "AcetoneISO::Warning", "Error: /usr/bin/fuseiso not found.\nPlease install fuseiso package.");
  26. return;
  27. }
  28. create_virtual_drives();
  29. QDir Home = QDir::home();
  30. QFile file(Home.path() + "/.acetoneiso/acetoneiso.conf");
  31. file.open(QIODevice::ReadOnly);//lo apro in sola lettura
  32. QString strd = (leggiRigo( 4, &file ));
  33. strd.remove(0,5);
  34. strd.chop(1);
  35. //controllo che se strd finisce con / allora si deve togliere.
  36. if( strd.endsWith( "/" ) ) {
  37. strd.chop(1);
  38. }
  39. QString isodamontare = immagine_con_percorso;
  40. QDir Temp = QDir::temp();
  41. Temp.cd("acetoneiso");
  42. QString percorsoTemp = Temp.path();
  43. QFile Mtab("/etc/mtab");//dichiaro un file Mtab che sarebbe /etc/mtab
  44. Mtab.open(QIODevice::ReadOnly);//lo apro in sola lettura
  45. QString str1 = (Mtab.readAll());//leggo il contenuto del file mtab
  46. QFileInfo fi(isodamontare);
  47. QString onlyfile = fi.fileName();
  48. QString image_with_path = isodamontare;
  49. QFile getfile;
  50. getfile.setFileName(isodamontare);
  51. float bignum = getfile.size();
  52. float divide;
  53. divide = (bignum / 1000) / 1000 ;
  54. QString percorsovirtuale;
  55. int x = 1;
  56. while( x < 8 ) {
  57. if( !str1.contains( Home.path() + "/virtual-drives/" + QString::number( x ) ) ) {
  58. percorsovirtuale = ( Home.path() + "/virtual-drives/" + QString::number( x ) );
  59. Monta( isodamontare, percorsovirtuale );
  60. while( FUse.waitForFinished() ) { //aspetto che finisca il processo fuse per controllare se ?ยจ stata montata
  61. }
  62. //check if udf filesystem
  63. QFile checkUDF(percorsovirtuale + "/readme.txt");
  64. checkUDF.open(QIODevice::ReadOnly);
  65. QByteArray bcheckUDF = checkUDF.readAll();
  66. QString readUDF = bcheckUDF;
  67. if (readUDF.contains("This disc contains a \"UDF\" ", Qt::CaseInsensitive) ) {
  68. QMessageBox::warning(this, "AcetoneISO::Warning",tr("This Image appears to have an UDF filesystem.\nTo correctly mount this image, open a terminal as root user and type:") + "\nmount -t auto -o loop \"" + image_with_path + "\" /$path_to_somwhere/ " );
  69. }
  70. openBrowser( percorsovirtuale, onlyfile, divide, percorsoTemp, image_with_path );
  71. break;
  72. }
  73. else {
  74. x++;
  75. }
  76. }
  77. if( x == 8 ) {
  78. QMessageBox::warning(this, "AcetoneISO::Warning",tr("All Virtual Drives are busy,\n"
  79. "Unmount some Virtual Drive first!"));
  80. }
  81. Mtab.close();
  82. file.close();
  83. }
  84. //gestisce l'apertura del file manager in base alle opzioni
  85. void acetoneiso::openFileManager(QString immagine_con_percorso) {
  86. QDir Home = QDir::home();//entro nella home utente
  87. QFile file(Home.path() + "/.acetoneiso/acetoneiso.conf");
  88. file.open(QIODevice::ReadOnly);//lo apro in sola lettura
  89. QString strc = (leggiRigo( 3, &file ));
  90. QString vd = Home.path() + "/virtual-drives/" + immagine_con_percorso;
  91. if(strc.contains("kde", Qt::CaseInsensitive)) { // se nelle impostazioni ho come browser kde
  92. BRowser.startDetached("kfmclient",QStringList() << "exec" << vd );
  93. }
  94. if(strc.contains("gnome", Qt::CaseInsensitive)) {
  95. BRowser.startDetached("nautilus",QStringList() << vd );
  96. }
  97. if(strc.contains("thunar", Qt::CaseInsensitive)) {
  98. BRowser.startDetached("thunar",QStringList() << vd );
  99. }
  100. if(strc.contains("lxde", Qt::CaseInsensitive)) {
  101. BRowser.startDetached("pcmanfm",QStringList() << vd );
  102. }
  103. /*
  104. if(strc.contains("nofilemanager", Qt::CaseInsensitive)) {
  105. QMessageBox::warning(this, "AcetoneISO::Warning",tr("Even though the image is mounted, in the options you specified to not open a file manager.\nIf you want to change this behaviour, please open Options and set file manager there."));
  106. }
  107. */
  108. file.close();
  109. }
  110. //funzione che smonta limmagine dal display del montaggio
  111. void acetoneiso::umount() {
  112. if (!listWidget_2->currentItem() == 0)
  113. {
  114. QString oggetto(listWidget_2->currentItem()->text());
  115. QChar periferica(oggetto[4]);
  116. QString f1_string(periferica);//
  117. QDir percorso = ( (QDir::home()).path() + "/virtual-drives/" + periferica );
  118. QDir Temp = QDir::temp();
  119. QFile f1;
  120. f1.setFileName( Temp.path() + "/acetoneiso/" + f1_string );
  121. QMessageBox msgBox;
  122. msgBox.setText(tr("You decided to unmount:\n") + oggetto + tr("\nAre you sure?"));
  123. msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
  124. switch (msgBox.exec()) {
  125. case QMessageBox::Yes:
  126. {
  127. //continue below
  128. }
  129. break;
  130. case QMessageBox::No:
  131. {
  132. return; //exit
  133. }
  134. break;
  135. default:
  136. // should never be reached
  137. break;
  138. }
  139. FUsermount.start("fusermount",QStringList() << "-u" << "-z" << percorso.path() );
  140. int riga = listWidget_2->currentRow() ;
  141. listWidget_2->takeItem( riga );
  142. f1.remove();
  143. FUsermount.waitForFinished();
  144. remove_virtual_drives();
  145. }
  146. else {
  147. QMessageBox::warning(this, "AcetoneISO::Warning",tr( "select an image to unmount from the virtual-drives display" ));
  148. }
  149. }
  150. //creo virtual drives
  151. void acetoneiso::create_virtual_drives() {
  152. QDir Home = QDir::home();
  153. Home.mkdir("virtual-drives");
  154. Home.cd("virtual-drives");
  155. Home.mkdir("1");
  156. Home.mkdir("2");
  157. Home.mkdir("3");
  158. Home.mkdir("4");
  159. Home.mkdir("5");
  160. Home.mkdir("6");
  161. Home.mkdir("7");
  162. Home.mkdir("dvd");
  163. }
  164. //cancello cartella virtual-drives
  165. void acetoneiso::remove_virtual_drives() {
  166. QDir Home = QDir::home();
  167. Home.rmdir("virtual-drives/1");
  168. Home.rmdir("virtual-drives/2");
  169. Home.rmdir("virtual-drives/3");
  170. Home.rmdir("virtual-drives/4");
  171. Home.rmdir("virtual-drives/5");
  172. Home.rmdir("virtual-drives/6");
  173. Home.rmdir("virtual-drives/7");
  174. Home.rmdir("virtual-drives/dvd");
  175. Home.rmdir("virtual-drives");
  176. }
  177. //carico tray icon
  178. void acetoneiso::load_trayicon() {
  179. AboutAction = new QAction(tr("About AcetoneISO"), this);
  180. connect(AboutAction, SIGNAL(triggered()), this, SLOT(on_actionAbout_activated() ));
  181. OptionsAction = new QAction(tr("Options"), this);
  182. connect(OptionsAction, SIGNAL(triggered()), this, SLOT(on_options_nda_activated() ));
  183. MountAction = new QAction(tr("Mount Image"), this);
  184. connect(MountAction, SIGNAL(triggered()), this, SLOT(mount()));
  185. restoreAction = new QAction(tr("&Restore"), this);
  186. connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
  187. quitAction = new QAction(tr("&Quit"), this);
  188. connect(quitAction, SIGNAL(triggered()), this, SLOT(quitto()));
  189. QIcon about_icon( ":/images/Acetino2.png" );
  190. QIcon options_icon( ":/images/aoptions.png" );
  191. QIcon mount_icon( ":/images/cdwriter_mount.png" );
  192. QIcon restore_icon( ":/images/file_manager.png" );
  193. QIcon exit_icon( ":/images/application-exit.png" );
  194. quitAction->setIcon(exit_icon);
  195. restoreAction->setIcon(restore_icon);
  196. MountAction->setIcon(mount_icon);
  197. AboutAction->setIcon(about_icon);
  198. OptionsAction->setIcon(options_icon);
  199. tray_has_loaded = false;
  200. //load tray icon
  201. QDir HomeT = QDir::home();
  202. QFile fileT(HomeT.path() + "/.acetoneiso/acetoneiso_advanced.conf");
  203. fileT.open(QIODevice::ReadOnly | QIODevice::Text);
  204. QString tray = fileT.readAll();
  205. if(tray.contains("enabletrayicon", Qt::CaseInsensitive)) {
  206. trayIcon = new QSystemTrayIcon();
  207. QIcon icon = QIcon(":/images/Acetino2.png");
  208. trayIcon->setIcon(icon);
  209. trayIcon->show();
  210. trayIcon->setToolTip(tr("AcetoneISO I love You!"));
  211. trayIconMenu = new QMenu(this);
  212. trayIconMenu->addAction(AboutAction);
  213. trayIconMenu->addAction(OptionsAction);
  214. trayIconMenu->addSeparator();
  215. trayIconMenu->addAction(MountAction);
  216. trayIconMenu->addSeparator();
  217. trayIconMenu->addAction(restoreAction);
  218. trayIconMenu->addAction(quitAction);
  219. trayIcon->setContextMenu(trayIconMenu);
  220. tray_has_loaded = true;
  221. connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
  222. }
  223. }
  224. //gestisco cosa fare quando lutente clicca su esci della tray icon
  225. void acetoneiso::quitto() {
  226. remove_virtual_drives();
  227. QCoreApplication::quit();
  228. }
  229. //gestisco quando cambia la selezione nel display del montaggio, cosi avverto il bottone smonta che cambia nome con il nome
  230. //dell'immagine
  231. void acetoneiso::mountdisplayClicked() {
  232. int size = listWidget_2->selectedItems().size();
  233. if (size < 1) {
  234. pushButton_2->setText(tr("Unmount"));
  235. actionUnmount_Image->setText(tr("Unmount Image"));
  236. pushButton_2->setEnabled(false);
  237. actionUnmount_Image->setEnabled(false);
  238. return;
  239. }
  240. pushButton_2->setEnabled(true);
  241. actionUnmount_Image->setEnabled(true);
  242. QString testo(listWidget_2->selectedItems()[0]->text()) ;
  243. QStringList smonta = testo.split(QRegExp("\\s+"));
  244. //gestisce lo spazio nel nome altrimenti lo taglia
  245. int strl = smonta.size();
  246. smonta.removeAt(strl - 1);
  247. smonta.removeAt(0);
  248. smonta.removeAt(0);
  249. strl = smonta.size();
  250. QString h = "";
  251. int ss = 0;
  252. while (ss < strl) {
  253. h = h.append(smonta[ss]);
  254. ss = ss + 1;
  255. }
  256. h = tr("Unmount") + " " + h;
  257. pushButton_2->setText(h);
  258. actionUnmount_Image->setText(h);
  259. }
  260. //nasconde display del processo
  261. void acetoneiso::hide_process_display() {
  262. textBrowser->clear();
  263. textBrowser->hide();
  264. pushButton_6->setEnabled(false);
  265. pushButton_6->hide();
  266. label_6->hide();
  267. verticalSpacer->changeSize( 0,0,QSizePolicy::Ignored );
  268. }
  269. //mostra il display del processo in esecuzione e i relativi bottoni, label ecc
  270. void acetoneiso::showProgressDisplay() {
  271. label_6->show();
  272. pushButton_6->show();
  273. pushButton_6->setEnabled(false);
  274. verticalSpacer->changeSize( 20,18,QSizePolicy::Fixed );
  275. textBrowser->clear();
  276. textBrowser->show();
  277. disable_all_button_processes();
  278. }
  279. //disable all buttons per evitare di fare doppi processi in contemporanea
  280. void acetoneiso::disable_all_button_processes() {
  281. menuConversion->setEnabled(false);
  282. menuUtilities->setEnabled(false);
  283. menuArchive_Manager->setEnabled(false);
  284. menuXvid_Videos->setEnabled(false);
  285. menuAudio->setEnabled(false);
  286. }
  287. //riabilita tutti i bottoni disabilitati (che evitavano piu di un processo in contemporanea
  288. void acetoneiso::restore_all_button_processes() {
  289. menuConversion->setEnabled(true);
  290. menuUtilities->setEnabled(true);
  291. menuArchive_Manager->setEnabled(true);
  292. menuXvid_Videos->setEnabled(true);
  293. menuAudio->setEnabled(true);
  294. }
  295. //fa il display del processo vidgen
  296. void acetoneiso::updateProgressDisplay_vidgen() {
  297. process_output = VIdgen->readAllStandardOutput();
  298. textBrowser->setPlainText(process_output);
  299. }
  300. //fa il display del processo flv
  301. void acetoneiso::updateProgressDisplay_flv() {
  302. process_output = FLv->readAllStandardOutput();
  303. textBrowser->setPlainText(process_output);
  304. }
  305. //fa il display del processo extractaudiofromvideo
  306. void acetoneiso::updateProgressDisplay_extractaudiofromvideo() {
  307. process_output = extractaudiofromvideo->readAllStandardOutput();
  308. textBrowser->setPlainText(process_output);
  309. }
  310. //fa il display del processo utube
  311. void acetoneiso::updateProgressDisplay_UTube() {
  312. process_output = UTube->readAllStandardOutput();
  313. textBrowser->setPlainText(process_output);
  314. }
  315. //fa il display di mkisofs
  316. void acetoneiso::updateProgressDisplay_MKisofs() {
  317. process_output = MKisofs->readAllStandardOutput();
  318. textBrowser->setPlainText(process_output);
  319. }
  320. //fa il display di convert to iso e extract (poweriso)
  321. void acetoneiso::updateProgressDisplay_POweriso() {
  322. process_output = POweriso->readAllStandardOutput();
  323. textBrowser->setPlainText(process_output);
  324. }
  325. //fa il display del convertitore mac dmg ad iso(macimg)
  326. void acetoneiso::updateProgressDisplay_MAcimg() {
  327. process_output = MAcimg->readAllStandardOutput();
  328. textBrowser->setPlainText(process_output);
  329. }
  330. //fa il display del backup cd audio
  331. void acetoneiso::updateProgressDisplay_BAckaudio() {
  332. process_output = BAckaudio->readAllStandardOutput();
  333. textBrowser->setPlainText(process_output);
  334. }
  335. //fa il display del rip cd psx
  336. void acetoneiso::updateProgressDisplay_PSxrip() {
  337. process_output = PSxrip->readAllStandardOutput();
  338. textBrowser->setPlainText(process_output);
  339. }
  340. //display del rip dvd a xvid pass 1
  341. void acetoneiso::updateProgressDisplay_RIp() {
  342. process_output = RIp->readAllStandardOutput();
  343. textBrowser->setPlainText(process_output);
  344. }
  345. //display del rip dvd a xvid pass 2
  346. void acetoneiso::updateProgressDisplay_RIp2() {
  347. process_output = RIp2->readAllStandardOutput();
  348. textBrowser->setPlainText(process_output);
  349. }
  350. //fa display del rar password
  351. void acetoneiso::updateProgressDisplay_RAR() {
  352. process_output = RAR->readAllStandardOutput();
  353. textBrowser->setPlainText(process_output);
  354. }