bool Speech::unload() { if(isLoaded()) { disconnect(mSpeechSourceAction, SIGNAL(triggered()), this, SLOT(pronounceSourceText())); disconnect(mSpeechResultAction, SIGNAL(triggered()), this, SLOT(pronounceResultText())); disconnect(mPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(removeTmpFile())); delete mSpeechSourceAction; delete mSpeechResultAction; delete mPlayer; mIsLoaded = false; } return true; }
bool Speech::load() { if(!isLoaded()) { mSpeechSourceAction = new QAction(QIcon(":icons/media-playback-start.png"), "Say it!", 0); mSpeechResultAction = new QAction(QIcon(":icons/media-playback-start.png"), "Say it!", 0); mPlayer = new QMediaPlayer; mTranslatorIface->addToolbarAction(mSpeechSourceAction, ITranslationWidget::SourceTextToolbar); mTranslatorIface->addToolbarAction(mSpeechResultAction, ITranslationWidget::ResultTextToolbar); connect(mSpeechSourceAction, SIGNAL(triggered()), this, SLOT(pronounceSourceText())); connect(mSpeechResultAction, SIGNAL(triggered()), this, SLOT(pronounceResultText())); connect(mPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(removeTmpFile())); mIsLoaded = true; } return true; }
void jsBridge::externalOpenResource(QString hash) { Resource *res = Resource::fromHash(hash); if (res == NULL) return; QString mime = res->mimeType(); QString filename = res->getFileName(); QByteArray data = res->getData(); delete res; if (filename.isEmpty()) filename = hash; if (mime == "application/pdf") { if (!filename.endsWith(".pdf", Qt::CaseInsensitive)) filename += ".pdf"; } else if (mime == "image/jpeg") { if (!filename.endsWith(".jpg", Qt::CaseInsensitive) && !filename.endsWith(".jpeg", Qt::CaseInsensitive)) filename += ".jpg"; } else if (mime == "image/png") { if (!filename.endsWith(".png", Qt::CaseInsensitive)) filename += ".png"; } else if (mime == "image/gif") { if (!filename.endsWith(".gif", Qt::CaseInsensitive)) filename += ".gif"; } QString tmpl = QDir::tempPath() + QDir::separator() + filename; QFile* f = new QFile(tmpl); if (!f->open(QIODevice::WriteOnly)) return; f->write(data); f->close(); files.enqueue(f); QTimer::singleShot(60000, this, SLOT(removeTmpFile())); QDesktopServices::openUrl(QUrl(tmpl)); }
XAP_UnixApp::~XAP_UnixApp() { removeTmpFile(); // FcFini(); }
void jsBridge::dragResource(QString hash) { Resource *res = Resource::fromHash(hash); if (res == NULL) return; QString mime = res->mimeType(); QString fileName = res->getFileName(); QByteArray data = res->getData(); QPixmap pix; if (res->isImage()) { pix.loadFromData(data); } else if (res->isPDF()) { pix.load(":/img/application-pdf.png"); } else { pix.load(":/img/application-octet-stream.png"); } delete res; if (fileName.isEmpty()) fileName = hash; if (mime == "application/pdf") { if (!fileName.endsWith(".pdf", Qt::CaseInsensitive)) fileName += ".pdf"; } else if (mime == "image/jpeg") { if (!fileName.endsWith(".jpg", Qt::CaseInsensitive) && !fileName.endsWith(".jpeg", Qt::CaseInsensitive)) fileName += ".jpg"; } else if (mime == "image/png") { if (!fileName.endsWith(".png", Qt::CaseInsensitive)) fileName += ".png"; } else if (mime == "image/gif") { if (!fileName.endsWith(".gif", Qt::CaseInsensitive)) fileName += ".gif"; } QString tmpl = QDir::tempPath() + QDir::separator() + fileName; QFile* f = new QFile(tmpl); if (!f->open(QIODevice::WriteOnly)) return; f->write(data); f->close(); files.enqueue(f); QTimer::singleShot(60000, this, SLOT(removeTmpFile())); QDrag *drag = new QDrag(new QWidget()); QMimeData *mimeData = new QMimeData; QFileInfo fileInfo(tmpl); QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath()); mimeData->setUrls(QList<QUrl>() << url); drag->setMimeData(mimeData); if (!pix.isNull()) drag->setPixmap(pix.scaled(128,128, Qt::KeepAspectRatio, Qt::SmoothTransformation)); drag->exec(Qt::CopyAction | Qt::MoveAction); }
jsBridge::~jsBridge() { while (!files.isEmpty()) removeTmpFile(); }