void DlgLoadDeckFromClipboard::actOK() { QString buffer = contentsEdit->toPlainText(); QTextStream stream(&buffer); DeckLoader *l = new DeckLoader; if (buffer.contains("<cockatrice_deck version=\"1\">")) { if (l->loadFromString_Native(buffer)) { deckList = l; accept(); } else { QMessageBox::critical(this, tr("Error"), tr("Invalid deck list.")); delete l; } } else if (l->loadFromStream_Plain(stream)) { deckList = l; accept(); } else { QMessageBox::critical(this, tr("Error"), tr("Invalid deck list.")); delete l; } }
void TabDeckStorage::actOpenLocalDeck() { QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); if (localDirModel->isDir(curLeft)) return; QString filePath = localDirModel->filePath(curLeft); DeckLoader deckLoader; if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat)) return; emit openDeckEditor(&deckLoader); }
void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandContainer &commandContainer) { if (r.response_code() != Response::RespOk) return; const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext); const Command_DeckDownload &cmd = commandContainer.session_command(0).GetExtension(Command_DeckDownload::ext); DeckLoader loader; if (!loader.loadFromRemote(QString::fromStdString(resp.deck()), cmd.deck_id())) return; emit openDeckEditor(&loader); }
void TabDeckEditor::actLoadDeck() { if (!confirmClose()) return; QFileDialog dialog(this, tr("Load deck")); dialog.setDirectory(settingsCache->getDeckPath()); dialog.setNameFilters(DeckLoader::fileNameFilters); if (!dialog.exec()) return; QString fileName = dialog.selectedFiles().at(0); DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName); DeckLoader *l = new DeckLoader; if (l->loadFromFile(fileName, fmt)) setDeck(l); else delete l; }
void DeckViewContainer::loadLocalDeck() { QFileDialog dialog(this, tr("Load deck")); dialog.setDirectory(settingsCache->getDeckPath()); dialog.setNameFilters(DeckLoader::fileNameFilters); if (!dialog.exec()) return; QString fileName = dialog.selectedFiles().at(0); DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName); DeckLoader deck; if (!deck.loadFromFile(fileName, fmt)) { QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded.")); return; } Command_DeckSelect cmd; cmd.set_deck(deck.writeToString_Native().toStdString()); PendingCommand *pend = static_cast<TabGame *>(parent())->prepareGameCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(deckSelectFinished(const Response &))); static_cast<TabGame *>(parent())->sendGameCommand(pend, playerId); }
void TabDeckStorage::actUpload() { QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); if (localDirModel->isDir(curLeft)) return; QString filePath = localDirModel->filePath(curLeft); QFile deckFile(filePath); QFileInfo deckFileInfo(deckFile); DeckLoader deck; if (!deck.loadFromFile(filePath, DeckLoader::CockatriceFormat)) return; if (deck.getName().isEmpty()) { bool ok; QString deckName = QInputDialog::getText(this, tr("Enter deck name"), tr("This decklist does not have a name.\nPlease enter a name:"), QLineEdit::Normal, deckFileInfo.completeBaseName(), &ok); if (!ok) return; if (deckName.isEmpty()) deckName = tr("Unnamed deck"); deck.setName(deckName); } QString targetPath; RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem(); if (!curRight) return; if (!dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight)) curRight = curRight->getParent(); targetPath = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight)->getPath(); Command_DeckUpload cmd; cmd.set_path(targetPath.toStdString()); cmd.set_deck_list(deck.writeToString_Native().toStdString()); PendingCommand *pend = client->prepareSessionCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(uploadFinished(Response, CommandContainer))); client->sendCommand(pend); }