Ejemplo n.º 1
0
void KateSession::init()
{
    // given file exists, use it to load some stuff ;)
    if(!m_sessionFileRel.isEmpty() && KGlobal::dirs()->exists(sessionFile()))
    {
        KSimpleConfig config(sessionFile(), true);

        if(m_sessionName.isEmpty())
        {
            // get the name out of the file
            if(m_sessionFileRel == "default.katesession")
                m_sessionName = i18n("Default Session");
            else
            {
                config.setGroup("General");
                m_sessionName = config.readEntry("Name", i18n("Unnamed Session"));
            }
        }

        // get the document count
        config.setGroup("Open Documents");
        m_documents = config.readUnsignedNumEntry("Count", 0);

        return;
    }

    // filename not empty, create the file
    // anders: When will this ever happen???
    if(!m_sessionFileRel.isEmpty())
    {
        kdDebug(13001) << "Kate::Session: initializing unexisting file!" << endl;
        // uhh, no name given
        if(m_sessionName.isEmpty())
        {
            if(m_sessionFileRel == "default.katesession")
                m_sessionName = i18n("Default Session");
            else
                m_sessionName = i18n("Session (%1)").arg(QTime::currentTime().toString(Qt::LocalDate));
        }

        // create the file, write name to it!
        KSimpleConfig config(sessionFile());
        config.setGroup("General");
        config.writeEntry("Name", m_sessionName);

        config.sync();
    }
}
Ejemplo n.º 2
0
bool BASE_SESSION_CLASS::load(string sessionFilename, bool& definitionFileLoaded, bool andBeginIt)

//  DESCRIPTION     : Load the session file parameters.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      :
//  NOTES           :
//<<===========================================================================
{
	definitionFileLoaded = true;

	// enable some logging
	if (loggerM_ptr)
	{
		// enable the base level logging
		UINT32 logMask = loggerM_ptr->getLogMask();
		logMask |= LOG_NONE;
		loggerM_ptr->setLogMask(logMask);
	}

    // Check if the given session filename contains a full path.
    // If so, get the session directory from the filename.
    unsigned int slashPosition = sessionFilename.find_last_of ('\\');
    if (slashPosition != sessionFilename.npos)
    {
        sessionDirectoryM = sessionFilename.substr (0, slashPosition + 1);
    }

	// cleanup previous session
	cleanup();

	// save session file name
	filenameM = sessionFilename;
	SESSION_FILE_CLASS	sessionFile(this, sessionFilename);

	// load the session file
	if (!sessionFile.execute())
	{
		// failed to load session file
		if (loggerM_ptr)
		{
			loggerM_ptr->text(LOG_NONE, 2, "%s %s", VAL_PREFIX_FAILED, sessionFile.getFilename());
		}

		// can't continue if session file load fails
		return false;
	}

	bool result = true;

	// check whether or not to begin the session after a successful load
	if (andBeginIt)
	{
		// begin the session
		result = begin(definitionFileLoaded);
	}

	// return result
	return result;
}
Ejemplo n.º 3
0
void SessionManager::saveSession()
{
    if (!m_safe || QWebSettings::globalSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled))
        return;
    m_safe = false;


    QFile sessionFile(m_sessionFilePath);
    if (!sessionFile.open(QFile::WriteOnly | QFile::Truncate))
    {
        kDebug() << "Unable to open session file" << sessionFile.fileName();
        return;
    }
    QTextStream out(&sessionFile);
    MainWindowList wl = rApp->mainWindowList();
    Q_FOREACH(const QWeakPointer<MainWindow> &w, wl)
    {
        out << "window\n";
        MainView *mv = w.data()->mainView();
        for (int i = 0 ; i < mv->count() ; i++)
        {
            out << mv->webTab(i)->url().toEncoded() << "\n";
        }

        // Current Tab for window
        out << "currenttab\n";
        out << mv->tabBar()->currentIndex() << "\n";
    }
Ejemplo n.º 4
0
KConfig *KateSession::configRead()
{
    if(m_sessionFileRel.isEmpty())
        return 0;

    if(m_readConfig)
        return m_readConfig;

    return m_readConfig = new KSimpleConfig(sessionFile(), true);
}
Ejemplo n.º 5
0
bool BASE_SESSION_CLASS::save()

//  DESCRIPTION     : Save the session parameters to file.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      :
//  NOTES           :
//<<===========================================================================
{
	SESSION_FILE_CLASS	sessionFile(this, filenameM);

	// save the session file
	return sessionFile.save();
}
Ejemplo n.º 6
0
KConfig *KateSession::configWrite()
{
    if(m_sessionFileRel.isEmpty())
        return 0;

    if(m_writeConfig)
        return m_writeConfig;

    m_writeConfig = new KSimpleConfig(sessionFile());
    m_writeConfig->setGroup("General");
    m_writeConfig->writeEntry("Name", m_sessionName);

    return m_writeConfig;
}
Ejemplo n.º 7
0
bool KateSession::rename(const QString &name)
{
    if(name.isEmpty() || m_sessionFileRel.isEmpty() || m_sessionFileRel == "default.katesession")
        return false;

    m_sessionName = name;

    KConfig config(sessionFile(), false, false);
    config.setGroup("General");
    config.writeEntry("Name", m_sessionName);
    config.sync();

    return true;
}
Ejemplo n.º 8
0
bool KateSession::create(const QString &name, bool force)
{
    if(!force && (name.isEmpty() || !m_sessionFileRel.isEmpty()))
        return false;

    delete m_writeConfig;
    m_writeConfig = 0;

    delete m_readConfig;
    m_readConfig = 0;

    m_sessionName = name;

    // get a usable filename
    int s = time(0);
    QCString tname;
    while(true)
    {
        tname.setNum(s++);
        KMD5 md5(tname);
        m_sessionFileRel = QString("%1.katesession").arg(md5.hexDigest().data());

        if(!KGlobal::dirs()->exists(sessionFile()))
            break;
    }

    // create the file, write name to it!
    KSimpleConfig config(sessionFile());
    config.setGroup("General");
    config.writeEntry("Name", m_sessionName);
    config.sync();

    // reinit ourselfs ;)
    init();

    return true;
}
Ejemplo n.º 9
0
// Only used internally
bool readSessionDocument(QDomDocument & document, const QString & sessionFilePath)
{
    QFile sessionFile(sessionFilePath);

    if (!sessionFile.exists())
        return false;

    if (!sessionFile.open(QFile::ReadOnly))
    {
        kDebug() << "Unable to open session file" << sessionFile.fileName();
        return false;
    }

    if (!document.setContent(&sessionFile, false))
    {
        kDebug() << "Unable to parse session file" << sessionFile.fileName();
        return false;
    }

    return true;
}
Ejemplo n.º 10
0
Archivo: job.cpp Proyecto: JoelB/BITS
bool Job::generateReport(QDateTime startDate,QDateTime endDate,QString filename)
{
	QString currentLine;
	QStringList sessionParts;
	int taskId;

	QMultiMap<int,taskSession> taskSessions;
	
	QFile sessionFile(attributeValues["Filename"].toString().replace(QString(".xml"),QString(".session")));
	if (!sessionFile.open(QIODevice::ReadOnly | QIODevice::Text))
		qDebug() << "Failed to session file!";

	while (!sessionFile.atEnd())
	{
		currentLine = QString(sessionFile.readLine());
		sessionParts = currentLine.split("%");
		taskSession tempsession;
		taskId = sessionParts.at(0).toInt();
		tempsession.start = QDateTime::fromString(sessionParts.at(1),Qt::ISODate);
		tempsession.end = QDateTime::fromString(sessionParts.at(2),Qt::ISODate);
		taskSessions.insert(taskId,tempsession);
	}
	sessionFile.close();
	
	QMap<int,int> totalTimes;
	QMapIterator<int,taskSession> iter(taskSessions);
	while (iter.hasNext())
	{
		iter.next();
		int timeSum = 0;
		QList<taskSession> sessions = taskSessions.values(iter.key());
		for (int i = 0; i < sessions.size(); i++)
		{
			taskSession tempSession = sessions.at(i);
			if (tempSession.start >= startDate && tempSession.end <= endDate) // session happened completely in range
				timeSum += tempSession.start.secsTo(tempSession.end);
			else if (tempSession.start <= startDate && tempSession.end <=endDate) // started out of range, ended in range
				timeSum += startDate.secsTo(tempSession.end);
			else if (tempSession.start >= startDate && tempSession.end >= endDate) // started in range, ended out of range
				timeSum += tempSession.start.secsTo(endDate);
			else if (tempSession.start <= startDate && tempSession.end >= endDate) // continued through entire range
				timeSum += startDate.secsTo(endDate);
		}
		totalTimes.insert(iter.key(),timeSum);
	}
	
	QFile reportFile(filename);
	if (!reportFile.open(QIODevice::WriteOnly | QIODevice::Text))
	{
		qDebug() << "Failed to open new report file!";
		return false;
	}
	
	QTextStream out(&reportFile);
	out << "Job Session Report for " << startDate.toString() << " to " << endDate.toString() << "\n\n";
	out << "Job Name: " << getAttributeValue("Name").toString() << "\n";
	out << "Job Start Date: " << getAttributeValue("StartDate").toDateTime().toString() << "\n";
	out << "Job End Date: " << getAttributeValue("EndDate").toDateTime().toString() << "\n\n";
	Task *tempTask;
	int allTime = 0;
	QStringList completedTasksOutput;
	QStringList otherTasksOutput;
	for (int i=0;i<taskCount();i++)
	{
		tempTask = getTask(i);
		QString name = tempTask->getAttributeValue("Name").toString();
		QString taskNum = QString::number(tempTask->getAttributeValue("TaskID").toInt()).prepend("   ");
		
		for (int j=taskNum.size(); j < 12; j++)
			taskNum.append(" ");
		for (int j=name.size(); j < 25; j++)
			name.append(" ");
		int timeSpent = totalTimes.value(tempTask->getAttributeValue("TaskID").toInt());
		allTime += timeSpent; // keep track of total time for percentages
		QString timeTotal = QString::number(timeSpent/3600) + "hr " + QString::number((timeSpent%3600)/60) + "min " + QString::number((timeSpent%3600)%60) + "sec";

		QDateTime completedDate = QDateTime::fromString(tempTask->getAttributeValue("Completed").toString(),Qt::ISODate);
		if (completedDate >= startDate && completedDate <= endDate)
			completedTasksOutput.append(QString(taskNum + name + timeTotal));
		else if (timeSpent > 0)
			otherTasksOutput.append(QString(taskNum + name + timeTotal));
	}
	completedTasksOutput.sort();
	otherTasksOutput.sort();
	
	out << "Tasks completed during selected time:\n\n";
	out << "\tTask ID     Task Name                 Time Spent            % of Total Time\n";
	out << "\t------------------------------------------------------------------------\n";
	QString tempOutput;
	for (int i = 0; i < completedTasksOutput.size(); i++)
	{
		tempOutput = completedTasksOutput.at(i);
		for (int j = tempOutput.size(); j < 65; j++)
			tempOutput.append(" ");
		QString percentage = QString::number(((double)totalTimes.value(tempOutput.left(10).simplified().toInt())/(double)allTime)*100.0,'f',2);
		out << "\t" << tempOutput << percentage << "\n";
	}
		
	out << "\n\nTasks worked on but not completed during selected time:\n\n";
	out << "\tTask ID     Task Name                 Time Spent            % of Total Time\n";
	out << "\t------------------------------------------------------------------------\n";
	for (int i = 0; i < otherTasksOutput.size(); i++)
	{
		tempOutput = otherTasksOutput.at(i);
		for (int j = tempOutput.size(); j < 65; j++)
			tempOutput.append(" ");
		QString percentage = QString::number((double)(totalTimes.value(tempOutput.left(10).simplified().toInt())/(double)allTime)*100.0,'f',2);
		out << "\t" << tempOutput << percentage << "\n";
	}
		
	reportFile.close();
	return true;
}
Ejemplo n.º 11
0
bool SessionManager::saveYourSession(int index)
{
    kDebug() << "SAVING YOUR OWN SESSION...";
    
    const QString & sessionPath = KStandardDirs::locateLocal("appdata" , QL1S("usersessions/"));
    const QString & sessionName = QL1S("ses") + QString::number(index);
    
    QFile sessionFile(sessionPath + sessionName);
    if (!sessionFile.open(QFile::WriteOnly | QFile::Truncate))
    {
        kDebug() << "Unable to open session file" << sessionFile.fileName();
        return false;
    }
    
    RekonqWindowList wl = rApp->rekonqWindowList();
    QDomDocument document("session");
    QDomElement session = document.createElement("session");
    document.appendChild(session);

    Q_FOREACH(const QWeakPointer<RekonqWindow> &w, wl)
    {
        if (w.data()->isPrivateBrowsingMode())
            continue;
        
        QDomElement window = document.createElement("window");
        int tabInserted = 0;

        window.setAttribute("name", w.data()->objectName());
        
        TabWidget *tw = w.data()->tabWidget();
        for (signed int tabNo = 0; tabNo < tw->count(); tabNo++)
        {
            KUrl u = tw->webWindow(tabNo)->url();

            tabInserted++;
            QDomElement tab = document.createElement("tab");
            tab.setAttribute("title", tw->webWindow(tabNo)->title()); // redundant, but needed for closedSites()
            // as there's not way to read out the historyData
            tab.setAttribute("url", u.url());
            if (tw->currentIndex() == tabNo)
            {
                tab.setAttribute("currentTab", 1);
            }
            if (tw->tabBar()->tabData(tabNo).toBool()) // pinned tab info
            {
                tab.setAttribute("pinned", 1);
            }
            QByteArray history;
            QDataStream historyStream(&history, QIODevice::ReadWrite);
            historyStream << *(tw->webWindow(tabNo)->page()->history());
            QDomCDATASection historySection = document.createCDATASection(history.toBase64());

            tab.appendChild(historySection);
            window.appendChild(tab);
        }
        
        if (tabInserted > 0)
            session.appendChild(window);
    }

    QTextStream TextStream(&sessionFile);
    document.save(TextStream, 2);
    sessionFile.close();

    return true;
}