bool Deck::importDana(QString fileName) { QFileInfo fi(fileName); QString baseName = fi.baseName().toLower(); QString tempFolder = utils::combinePaths(tempPath(), baseName); QString deckPath = utils::combinePaths(tempFolder, "deck.xml"); QString iconPath = utils::combinePaths(tempFolder, "icon.png"); utils::createDirectory(tempFolder); Compressor c; if(!c.decompressFolder(fileName, tempFolder)) { return false; } /// importFromXml(deckPath); utils::removeFile(deckPath); utils::copyDirectory(getDeckPath(), tempFolder); /// load icon pixmap loadPixmap( iconPath ); return true; }
bool Deck::exportToDana(QString fileName) { QFileInfo fi(fileName); QString baseName = fi.baseName().toLower(); QString tempFolder = utils::combinePaths(tempPath(), baseName); QString deckFile = utils::combinePaths(tempFolder, "deck.xml"); utils::removeDirectory(tempFolder); utils::createDirectory(tempFolder); if(!exportToXml(deckFile)) return false; utils::copyDirectory(tempFolder, getDeckPath()); Compressor c; if(!c.compressFolder(tempFolder, fileName)) { return false; } return true; }
void Deck::Merge(Deck *dst, int option, int *stats) { /// first of all, open the deck! if(!openDeck()) return; int rightCount = dst->getCardsNo(); int leftCount = this->getCardsNo(); Card *rightCard=0; Card *leftCard=0; bool hasMerged = false; if(stats) *stats = 0; QList<Card*> cards; for(int i=0; i < rightCount; i++) { rightCard = dst->getCardAt(i); hasMerged = false; for(int j=0; j < leftCount; j++) { leftCard = this->getCardAt(j); if(leftCard->compare(*rightCard)) { hasMerged = true; switch(option) { case AcceptSource: break; case AcceptTarget: leftCard->updateBack(rightCard->getBack()); break; case AutoMerge: hasMerged = false; break; } break; } } if(!hasMerged) { if(stats) (*stats)++; Card *card = new Card(*rightCard); cards.append(card); } } /// flush list to deck for(int index = 0; index < cards.size(); index++) { addCard(cards[index]); } /// update deck info if(option!=AcceptSource) { name = dst->getName(); desc = dst->getDesc(); author = dst->getAuthor(); tags = dst->getTags(); pixmap = dst->getPixmap(); format = dst->getFormat(); flags = dst->getFlags(); } utils::copyDirectory(getDeckPath(), dst->getDeckPath()); saveDeck(); }
bool Deck::importMnemosyne(QString fileName) { QFileInfo fi(fileName); QString baseName = fi.baseName().toLower(); QString tempFolder = utils::combinePaths(tempPath(), baseName); QString metadataPath = utils::combinePaths(tempFolder, "METADATA"); QString cardsPath = utils::combinePaths(tempFolder, "cards.xml"); utils::createDirectory(tempFolder); Compressor c; if(!c.decompressFolder(fileName, tempFolder)) { return false; } /// import metadata /// QTextStream s; QFile metadataFile(metadataPath); metadataFile.open(QIODevice::ReadOnly | QIODevice::Text); if(!metadataFile.isOpen()) return false; s.setDevice(&metadataFile); s.setCodec("UTF-8"); QStringList sl; QString l = s.readLine(); while (!s.atEnd()) { sl = l.split(":"); if(sl.size()>1) { if(sl[0]=="tags") setTags(sl[1]); else if(sl[0]=="notes") setDesc(sl[1]); else if(sl[0]=="author_name") setAuthor(sl[1]); else if(sl[0]=="card_set_name") setName(sl[1]); } l = s.readLine(); } /// read cards QDomDocument domDocument; QString errorStr; int errorLine; int errorColumn; QString front, back, level; QFile cardsFile(cardsPath); cardsFile.open(QIODevice::ReadOnly | QIODevice::Text); if(!cardsFile.isOpen()) return false; if (!domDocument.setContent(&cardsFile, true, &errorStr, &errorLine, &errorColumn)) { qDebug() << QString("Parse error at line %1, column %2:\n%3") .arg(errorLine) .arg(errorColumn) .arg(errorStr); return false; } QDomElement root = domDocument.documentElement(); QString rootName = root.tagName().toLower(); if (rootName == "opensm2sync") { QDomNodeList nodes = root.elementsByTagName("log"); QDomNode node; QDomElement elnode; int count = nodes.count(); for(int no = 0; no < count; no++) { node = nodes.at(no); if(node.attributes().namedItem("type").nodeValue()=="16") { elnode = node.firstChildElement("f"); front = elnode.text(); elnode = node.firstChildElement("b"); back = elnode.text(); if(!front.isEmpty()) { Card *card = new Card(); card->updateFront(front); card->updateBack(back); addCard(card); } } } } metadataFile.close(); cardsFile.close(); utils::removeFile(metadataPath); utils::removeFile(cardsPath); utils::copyDirectory(getDeckPath(), tempFolder); return true; }
GeneralSettingsPage::GeneralSettingsPage() { QString setLanguage = settingsCache->getLang(); QStringList qmFiles = findQmFiles(); for (int i = 0; i < qmFiles.size(); i++) { QString langName = languageName(qmFiles[i]); languageBox.addItem(langName, qmFiles[i]); if ((qmFiles[i] == setLanguage) || (setLanguage.isEmpty() && langName == tr("English"))) languageBox.setCurrentIndex(i); } picDownloadCheckBox.setChecked(settingsCache->getPicDownload()); picDownloadHqCheckBox.setChecked(settingsCache->getPicDownloadHq()); pixmapCacheEdit.setMinimum(PIXMAPCACHE_SIZE_MIN); // 2047 is the max value to avoid overflowing of QPixmapCache::setCacheLimit(int size) pixmapCacheEdit.setMaximum(PIXMAPCACHE_SIZE_MAX); pixmapCacheEdit.setSingleStep(64); pixmapCacheEdit.setValue(settingsCache->getPixmapCacheSize()); pixmapCacheEdit.setSuffix(" MB"); picDownloadHqCheckBox.setChecked(settingsCache->getPicDownloadHq()); picDownloadCheckBox.setChecked(settingsCache->getPicDownload()); highQualityURLEdit = new QLineEdit(settingsCache->getPicUrlHq()); highQualityURLEdit->setEnabled(settingsCache->getPicDownloadHq()); connect(&clearDownloadedPicsButton, SIGNAL(clicked()), this, SLOT(clearDownloadedPicsButtonClicked())); connect(&languageBox, SIGNAL(currentIndexChanged(int)), this, SLOT(languageBoxChanged(int))); connect(&picDownloadCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPicDownload(int))); connect(&picDownloadHqCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPicDownloadHq(int))); connect(&pixmapCacheEdit, SIGNAL(valueChanged(int)), settingsCache, SLOT(setPixmapCacheSize(int))); connect(&picDownloadHqCheckBox, SIGNAL(clicked(bool)), this, SLOT(setEnabledStatus(bool))); connect(highQualityURLEdit, SIGNAL(textChanged(QString)), settingsCache, SLOT(setPicUrlHq(QString))); QGridLayout *personalGrid = new QGridLayout; personalGrid->addWidget(&languageLabel, 0, 0); personalGrid->addWidget(&languageBox, 0, 1); personalGrid->addWidget(&pixmapCacheLabel, 1, 0, 1, 1); personalGrid->addWidget(&pixmapCacheEdit, 1, 1, 1, 1); personalGrid->addWidget(&picDownloadCheckBox, 2, 0, 1, 2); personalGrid->addWidget(&picDownloadHqCheckBox, 3, 0, 1, 2); personalGrid->addWidget(&clearDownloadedPicsButton, 4, 0, 1, 1); personalGrid->addWidget(&highQualityURLLabel, 5, 0, 1, 1); personalGrid->addWidget(highQualityURLEdit, 5, 1, 1, 1); personalGrid->addWidget(&highQualityURLLinkLabel, 6, 1, 1, 1); highQualityURLLinkLabel.setTextInteractionFlags(Qt::LinksAccessibleByMouse); highQualityURLLinkLabel.setOpenExternalLinks(true); personalGroupBox = new QGroupBox; personalGroupBox->setLayout(personalGrid); deckPathEdit = new QLineEdit(settingsCache->getDeckPath()); deckPathEdit->setReadOnly(true); QPushButton *deckPathButton = new QPushButton("..."); connect(deckPathButton, SIGNAL(clicked()), this, SLOT(deckPathButtonClicked())); replaysPathEdit = new QLineEdit(settingsCache->getReplaysPath()); replaysPathEdit->setReadOnly(true); QPushButton *replaysPathButton = new QPushButton("..."); connect(replaysPathButton, SIGNAL(clicked()), this, SLOT(replaysPathButtonClicked())); picsPathEdit = new QLineEdit(settingsCache->getPicsPath()); picsPathEdit->setReadOnly(true); QPushButton *picsPathButton = new QPushButton("..."); connect(picsPathButton, SIGNAL(clicked()), this, SLOT(picsPathButtonClicked())); cardDatabasePathEdit = new QLineEdit(settingsCache->getCardDatabasePath()); cardDatabasePathEdit->setReadOnly(true); QPushButton *cardDatabasePathButton = new QPushButton("..."); connect(cardDatabasePathButton, SIGNAL(clicked()), this, SLOT(cardDatabasePathButtonClicked())); tokenDatabasePathEdit = new QLineEdit(settingsCache->getTokenDatabasePath()); tokenDatabasePathEdit->setReadOnly(true); QPushButton *tokenDatabasePathButton = new QPushButton("..."); connect(tokenDatabasePathButton, SIGNAL(clicked()), this, SLOT(tokenDatabasePathButtonClicked())); QGridLayout *pathsGrid = new QGridLayout; pathsGrid->addWidget(&deckPathLabel, 0, 0); pathsGrid->addWidget(deckPathEdit, 0, 1); pathsGrid->addWidget(deckPathButton, 0, 2); pathsGrid->addWidget(&replaysPathLabel, 1, 0); pathsGrid->addWidget(replaysPathEdit, 1, 1); pathsGrid->addWidget(replaysPathButton, 1, 2); pathsGrid->addWidget(&picsPathLabel, 2, 0); pathsGrid->addWidget(picsPathEdit, 2, 1); pathsGrid->addWidget(picsPathButton, 2, 2); pathsGrid->addWidget(&cardDatabasePathLabel, 3, 0); pathsGrid->addWidget(cardDatabasePathEdit, 3, 1); pathsGrid->addWidget(cardDatabasePathButton, 3, 2); pathsGrid->addWidget(&tokenDatabasePathLabel, 4, 0); pathsGrid->addWidget(tokenDatabasePathEdit, 4, 1); pathsGrid->addWidget(tokenDatabasePathButton, 4, 2); pathsGroupBox = new QGroupBox; pathsGroupBox->setLayout(pathsGrid); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(personalGroupBox); mainLayout->addWidget(pathsGroupBox); setLayout(mainLayout); }