Пример #1
0
nsresult
nsOperaProfileMigrator::CopyCookies(PRBool aReplace)
{
    nsresult rv = NS_OK;

    nsCOMPtr<nsIFile> temp;
    mOperaProfile->Clone(getter_AddRefs(temp));
    nsCOMPtr<nsILocalFile> historyFile(do_QueryInterface(temp));

    historyFile->Append(OPERA_COOKIES_FILE_NAME);

    nsCOMPtr<nsIInputStream> fileStream;
    NS_NewLocalFileInputStream(getter_AddRefs(fileStream), historyFile);
    if (!fileStream)
        return NS_ERROR_OUT_OF_MEMORY;

    nsOperaCookieMigrator* ocm = new nsOperaCookieMigrator(fileStream);
    if (!ocm)
        return NS_ERROR_OUT_OF_MEMORY;

    rv = ocm->Migrate();

    if (ocm) {
        delete ocm;
        ocm = nsnull;
    }

    return rv;
}
HistoryModel::HistoryModel(QObject *parent)
    : QAbstractListModel(parent)
{
    // Set role names to access data from QML
    QHash<int, QByteArray> roles;
    roles[TimeRole] = "time";
    roles[HeartRateRole] = "heartRate";
    setRoleNames(roles);

    // Read info file if is exists
    QFile historyFile("/home/user/MyDocs/heartrate.csv");
    if (historyFile.exists() && historyFile.open(QIODevice::ReadOnly)) {
        QTextStream in(&historyFile);
        while (!in.atEnd()) {
            QString line = in.readLine();
            QStringList values = line.split(" ");
            if (values.length() > 1) {
                QDateTime time = QDateTime::fromString(values[0], Qt::ISODate);
                int value = values[1].toInt();
                HeartRateMeasurement measurement(time, value);
                m_data.append(measurement);
            }
        }
        historyFile.close();
    }
}
Пример #3
0
QString History::getMessage(qint64 offset) {
	QString data;

	lmcSettings settings;
	QString path = historyFile();

	if(!QFile::exists(path))
		return data;

	QFile file(path);
	if(!file.open(QIODevice::ReadOnly))
		return data;

	QDataStream stream(&file);

	QString marker;
	int length;
	QByteArray buffer;

	stream.device()->seek(offset);
	stream >> marker;
	stream >> length;
	stream >> buffer;
	
	data = QString::fromUtf8(buffer, buffer.length());

	file.close();
	return data;
}
Пример #4
0
MissileSim::MissileSim(){
    timer.start();
    std::string historyFile("/Users/christianjhoward/history.txt");
    setSimHistoryPath(historyFile);
    state.printFrequency = 100;
    numMC = 1;
    writeSimHistory = true;
}
void CountryCollection::WriteHistory(const std::string& path) const
{
  for (const auto& countryPair : countries)
  {
    const auto& country = countryPair.second;
    std::ofstream historyFile(path + '\\' + country.GetTag() + " - " + NormalizeName(country.GetName()) + ".txt");
    if (!historyFile)
      throw std::runtime_error("Error creating common history file for country " + country.GetName());
    country.WriteHistory(historyFile);
  }
}
Пример #6
0
bool SxVersionedFile::initHistory( const QString &file  )
{
	QDir history( historyFile( file ) );
	if( history.exists() )
		return true;

	if( !history.mkpath( historyFile( file ) ) )
	{
		return false;
	}

	// Read source file, and copy it into the first revision.
	QFile fileIn( file );
	if( !fileIn.open(QIODevice::ReadOnly) )
		return false;

	bool result = checkInHead( &fileIn, &history );
	fileIn.close();
	return result;
}
Пример #7
0
void MainWindow::closeEvent(QCloseEvent *event)
{
    QFile historyFile(historyFullPath);
    if (historyFile.open(QIODevice::WriteOnly)) {
        history.write(historyFile);
        historyFile.close();
    } else
    {
        //TODO log: history unwritable
    }
    QMainWindow::closeEvent(event);
}
Пример #8
0
void HelpBrowser::closeEvent(QCloseEvent * event)
{
	delete menuModel;

	// no need to delete child widgets, Qt does it all for us
	// bookmarks
	QFile bookFile(bookmarkFile());
	if (bookFile.open(QIODevice::WriteOnly))
	{
		QTextStream stream(&bookFile);
		stream.setCodec("UTF-8");
		stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		stream << "<bookmarks>\n";
		QTreeWidgetItemIterator it(helpNav->bookmarksView);
		while (*it) 
		{
			if (bookmarkIndex.contains((*it)->text(0)))
			{
				QString pagetitle(bookmarkIndex.value((*it)->text(0)).first);
				QString filename(bookmarkIndex.value((*it)->text(0)).second);
				stream << "\t<item title=\"" << (*it)->text(0) << "\" pagetitle=\"" << pagetitle << "\" url=\"" << filename << "\" />\n";
			}
			++it;
		}
		stream << "</bookmarks>\n";
		bookFile.close();
	}
	// history
  	QFile histFile(historyFile());
	if (histFile.open(QIODevice::WriteOnly))
	{
		QTextStream stream(&histFile);
		stream.setCodec("UTF-8");
		stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		stream << "<history>\n";
		for (QMap<QAction*,histd2>::Iterator it = mHistory.begin() ; it != mHistory.end(); ++it)
			stream << "\t<item title=\"" << it.value().title << "\" url=\"" << it.value().url << "\" />\n";
		stream << "</history>\n";
		histFile.close();
	}
	// size
	prefs->set("xsize", width());
	prefs->set("ysize", height());

	emit closed();
}
void HistoryModel::append(const HeartRateMeasurement &measurement)
{
    qDebug() << __PRETTY_FUNCTION__;

    m_data.append(measurement);

    // Read info file if is exists
    QFile historyFile("/home/user/MyDocs/heartrate.csv");
    if (historyFile.open(QIODevice::Append)) {
        historyFile.write(measurement.time().toString(Qt::ISODate).toUtf8().constData());
        historyFile.write(" ");
        const QString value = QString("%1").arg(measurement.value());
        historyFile.write(value.toUtf8().constData());
        historyFile.write("\n");
        historyFile.close();
    }
}
Пример #10
0
void WebHistory::saveHistory() const
{
	QDir dir;
        dir.mkpath(QDir::homePath() + "/.mosaix");
        dir.cd(QDir::homePath() + "/.mosaix");
	QByteArray historyArray;
	QFile historyFile(dir.path() + "/history");
	historyFile.open(QIODevice::WriteOnly);
	foreach(WebHistoryItem * item, pItems)
	{
		historyArray += item->url().toUtf8();
		historyArray += '\n';
		historyArray += item->title().toUtf8();
		historyArray += '\n';
		historyArray += item->dateTime().
							toString("dd.MM.yyyy hh:mm").
							toUtf8();
		historyArray += '\n';
//		historyArray += item->icon();
//		historyArray += '\n';
	}
Пример #11
0
int History::save(QString user, QDateTime date, QString* lpszData) {
	lmcSettings settings;
	QString path = historyFile();
	
	QDir dir = QFileInfo(path).dir();
	if(!dir.exists())
		dir.mkpath(dir.absolutePath());

	if(!QFile::exists(path))
		create(path);

	QFile file(path);
	if(!file.open(QIODevice::ReadWrite))
		return -1;

	QDataStream stream(&file);

	DBHeader header = readHeader(&stream);
	if(header.marker.compare(HC_DBMARKER) != 0) {
		file.close();
		return -1;
	}

	qint64 dataPos = insertData(&stream, lpszData);
	qint64 newIndex = insertIndex(&stream, dataPos, user, date);
	updateIndex(&stream, header.last, newIndex);

	header.count++;
	header.first = (header.first == 0) ? newIndex : header.first;
	header.last = newIndex;

	writeHeader(&stream, &header);

	file.close();
	return 0;
}
Пример #12
0
QList<MsgInfo> History::getList(void) {
	QList<MsgInfo> list;

	lmcSettings settings;
	QString path = historyFile();

	if(!QFile::exists(path))
		return list;

	QFile file(path);
	if(!file.open(QIODevice::ReadOnly))
		return list;

	QDataStream stream(&file);

	DBHeader header = readHeader(&stream);
	qint64 next = header.first;
	
	QString marker;
	qint64 offset;
	qint64 date;
	QString name;
	
	while(next != 0) {
		stream.device()->seek(next);
		MsgInfo info;
		stream >> marker;
		stream >> next;
		stream >> offset;
		stream >> date;
		stream >> name;
		list.append(MsgInfo(name, QDateTime::fromMSecsSinceEpoch(date), offset));
	}

	return list;
}
Пример #13
0
nsresult
nsOperaProfileMigrator::CopyHistoryBatched(PRBool aReplace)
{
    nsCOMPtr<nsIBrowserHistory> hist(do_GetService(NS_GLOBALHISTORY2_CONTRACTID));

    nsCOMPtr<nsIFile> temp;
    mOperaProfile->Clone(getter_AddRefs(temp));
    nsCOMPtr<nsILocalFile> historyFile(do_QueryInterface(temp));
    historyFile->Append(OPERA_HISTORY_FILE_NAME);

    nsCOMPtr<nsIInputStream> fileStream;
    NS_NewLocalFileInputStream(getter_AddRefs(fileStream), historyFile);
    if (!fileStream) return NS_ERROR_OUT_OF_MEMORY;

    nsCOMPtr<nsILineInputStream> lineStream = do_QueryInterface(fileStream);

    nsCAutoString buffer, url;
    nsAutoString title;
    PRTime lastVisitDate;
    PRBool moreData = PR_FALSE;

    enum { TITLE, URL, LASTVISIT } state = TITLE;

    // Format is "title\nurl\nlastvisitdate"
    do {
        nsresult rv = lineStream->ReadLine(buffer, &moreData);
        if (NS_FAILED(rv))
            return rv;

        switch (state) {
        case TITLE:
            CopyUTF8toUTF16(buffer, title);
            state = URL;
            break;
        case URL:
            url = buffer;
            state = LASTVISIT;
            break;
        case LASTVISIT:
            // Opera time format is a second offset, PRTime is a microsecond offset
            nsresult err;
            lastVisitDate = buffer.ToInteger(&err);

            PRInt64 temp, million;
            LL_I2L(temp, lastVisitDate);
            LL_I2L(million, PR_USEC_PER_SEC);
            LL_MUL(lastVisitDate, temp, million);

            nsCOMPtr<nsIURI> uri;
            NS_NewURI(getter_AddRefs(uri), url);
            if (uri)
                hist->AddPageWithDetails(uri, title.get(), lastVisitDate);

            state = TITLE;
            break;
        }
    }
    while (moreData);

    return NS_OK;
}
Пример #14
0
void HistoryManager::save()
{
    QSettings settings;
    settings.beginGroup(QLatin1String("history"));
    settings.setValue(QLatin1String("historyLimit"), m_historyLimit);

    bool saveAll = m_lastSavedUrl.isEmpty();
    int first = m_history.count() - 1;
    if (!saveAll) {
        // find the first one to save
        for (int i = 0; i < m_history.count(); ++i) {
            if (m_history.at(i).url == m_lastSavedUrl) {
                first = i - 1;
                break;
            }
        }
    }
    if (first == m_history.count() - 1)
        saveAll = true;

    QString directory = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
    if (directory.isEmpty())
        directory = QDir::homePath() + QLatin1String("/.") + QCoreApplication::applicationName();
    if (!QFile::exists(directory)) {
        QDir dir;
        dir.mkpath(directory);
    }

    QFile historyFile(directory + QLatin1String("/history"));
    // When saving everything use a temporary file to prevent possible data loss.
    QTemporaryFile tempFile;
    tempFile.setAutoRemove(false);
    bool open = false;
    if (saveAll) {
        open = tempFile.open();
    } else {
        open = historyFile.open(QFile::Append);
    }

    if (!open) {
        qWarning() << "Unable to open history file for saving"
                   << (saveAll ? tempFile.fileName() : historyFile.fileName());
        return;
    }

    QDataStream out(saveAll ? &tempFile : &historyFile);
    for (int i = first; i >= 0; --i) {
        QByteArray data;
        QDataStream stream(&data, QIODevice::WriteOnly);
        HistoryItem item = m_history.at(i);
        stream << HISTORY_VERSION << item.url << item.dateTime << item.title;
        out << data;
    }
    tempFile.close();

    if (saveAll) {
        if (historyFile.exists() && !historyFile.remove())
            qWarning() << "History: error removing old history." << historyFile.errorString();
        if (!tempFile.rename(historyFile.fileName()))
            qWarning() << "History: error moving new history over old." << tempFile.errorString() << historyFile.fileName();
    }
    m_lastSavedUrl = m_history.value(0).url;
}
Пример #15
0
void HistoryManager::load()
{
    loadSettings();

    QFile historyFile(QStandardPaths::writableLocation(QStandardPaths::DataLocation)
        + QLatin1String("/history"));
    if (!historyFile.exists())
        return;
    if (!historyFile.open(QFile::ReadOnly)) {
        qWarning() << "Unable to open history file" << historyFile.fileName();
        return;
    }

    QList<HistoryItem> list;
    QDataStream in(&historyFile);
    // Double check that the history file is sorted as it is read in
    bool needToSort = false;
    HistoryItem lastInsertedItem;
    QByteArray data;
    QDataStream stream;
    QBuffer buffer;
    stream.setDevice(&buffer);
    while (!historyFile.atEnd()) {
        in >> data;
        buffer.close();
        buffer.setBuffer(&data);
        buffer.open(QIODevice::ReadOnly);
        quint32 ver;
        stream >> ver;
        if (ver != HISTORY_VERSION)
            continue;
        HistoryItem item;
        stream >> item.url;
        stream >> item.dateTime;
        stream >> item.title;

        if (!item.dateTime.isValid())
            continue;

        if (item == lastInsertedItem) {
            if (lastInsertedItem.title.isEmpty() && !list.isEmpty())
                list[0].title = item.title;
            continue;
        }

        if (!needToSort && !list.isEmpty() && lastInsertedItem < item)
            needToSort = true;

        list.prepend(item);
        lastInsertedItem = item;
    }
    if (needToSort)
        qSort(list.begin(), list.end());

    setHistory(list, true);

    // If we had to sort re-write the whole history sorted
    if (needToSort) {
        m_lastSavedUrl = QString();
        m_saveTimer->changeOccurred();
    }
}
Пример #16
0
void MainWindow::readResources()
{
    QDir portableDir = QDir::currentPath();

    int kanjidicState = kanjidic.readResources(portableDir);
    if(kanjidicState == KanjiDB::noDataRead)
    {
        //TODO log not portable mode
        kanjidicState = kanjidic.readResources(resourceDir);
    } else {
        resourceDir = portableDir;
    }

    if(kanjidicState == KanjiDB::noDataRead)
        QMessageBox::warning(this, tr("Kanjidic resources"),
                          tr("Unable to read resources. No kanji data will be available.\nError message:\n%1")
                          .arg(kanjidic.errorString()));
    else
    {
        if(kanjidicState == KanjiDB::baseDataRead)
            QMessageBox::warning(this, tr("Kanjidic resources"),
                              tr("Unable to read some resources, some radical functionalities will be missing.\nError message:\n%1")
                              .arg(kanjidic.errorString()));
        else if(kanjidicState == KanjiDB::allDataReadButNotSaved)
            QMessageBox::warning(this, tr("Kanjidic resources"),
                              tr("Unable to save resource indexes. Error message:\n%1")
                              .arg(kanjidic.errorString()));

        statusBar()->showMessage(tr("File loaded"), 2000);
        searchBar->radicalSelectionForm()->setKanjiDB(kanjidic);
        searchBar->componentSelectionForm()->setKanjiDB(kanjidic);
        QFile historyFile(resourceDir.absolutePath().append("/").append(historyFilename));
        historyFullPath = historyFile.fileName();
        if (historyFile.open(QIODevice::ReadOnly)) {
            history.read(historyFile);
            historyFile.close();
        } else
        {
            //TODO log: no history found
        }
    }


//    QFile tmp1("out_components");
//    tmp1.open(QIODevice::WriteOnly);
//    QTextStream stream1(&tmp1);
//    stream1.setCodec(QTextCodec::codecForName("UTF-8"));
//    for(int i = 0; i < kanjidic.getAllComponents().size(); ++i)
//        stream1 << QString::number(kanjidic.getComponentById(i)->getUnicode()) << " " << kanjidic.getComponentById(i)->getLiteral() << endl;
//    tmp1.close();

//    QFile tmp2("out_radicals");
//    tmp2.open(QIODevice::WriteOnly);
//    QTextStream stream2(&tmp2);
//    stream2.setCodec(QTextCodec::codecForName("UTF-8"));
//    for(int i = 0; i < Radicals::radicalsSize; ++i)
//    {
//        QChar ch = Radicals::radicals[i].at(0);
//        stream2 << QString::number(ch.unicode()) << " " << ch << endl;
//        foreach(Unicode c, kanjidic.getRadicalVariant(ch.unicode())->getUnicodeVariants())
//            stream2 << QString::number(c) << " " << kanjidic.getRadicalVariant(c)->getLiteral() << endl;
//    }
//    tmp2.close();
}