<commit_before>#include "DeviceVcfFile.h"
#include <assert.h>
#include <QFileInfo>
#include "VCardParser.h"
#include "Exceptions.h"





DeviceVcfFile::DeviceVcfFile():
	m_ContactBook(new ContactBook(tr("Contacts")))
{
}





QString DeviceVcfFile::displayName() const
{
	return m_DisplayName;
}





void DeviceVcfFile::start()
{
	if (m_VcfFileName.isEmpty())
	{
		// Invalid settings
		return;
	}

	// Load the VCF data:
	QFile f(m_VcfFileName);
	if (!f.open(QFile::ReadOnly | QFile::Text))
	{
		m_DisplayName = tr("%1 (Cannot open file)").arg(m_VcfFileNameBase);
		return;
	}
	try
	{
		VCardParser::parse(f, m_ContactBook);
	}
	catch (const EParseError & exc)
	{
		m_DisplayName = tr("%1 (Cannot parse file: %2)")
			.arg(m_VcfFileNameBase)
			.arg(QString::fromStdString(exc.m_Message));
	}
	catch (const EException &)
	{
		m_DisplayName = tr("%1 (Cannot parse file)").arg(m_VcfFileNameBase);
		return;
	}
}





void DeviceVcfFile::stop()
{
	// Nothing needed
}





bool DeviceVcfFile::isOnline() const
{
	return !m_VcfFileName.isEmpty();
}





bool DeviceVcfFile::load(const QJsonObject & a_Config)
{
	m_VcfFileName = a_Config["fileName"].toString();

	// Strip away the path:
	QFileInfo fi(m_VcfFileName);
	m_VcfFileNameBase = fi.fileName();

	return true;
}





QJsonObject DeviceVcfFile::save() const
{
	QJsonObject res;
	res["fileName"] = m_VcfFileName;
	return res;
}




<commit_msg>DeviceVcfFile: Fixed device display name.<commit_after>#include "DeviceVcfFile.h"
#include <assert.h>
#include <QFileInfo>
#include "VCardParser.h"
#include "Exceptions.h"





DeviceVcfFile::DeviceVcfFile():
	m_ContactBook(new ContactBook(tr("Contacts")))
{
}





QString DeviceVcfFile::displayName() const
{
	return m_DisplayName;
}





void DeviceVcfFile::start()
{
	if (m_VcfFileName.isEmpty())
	{
		// Invalid settings
		return;
	}

	// Load the VCF data:
	QFile f(m_VcfFileName);
	if (!f.open(QFile::ReadOnly | QFile::Text))
	{
		m_DisplayName = tr("%1 (Cannot open file)").arg(m_VcfFileNameBase);
		return;
	}
	try
	{
		VCardParser::parse(f, m_ContactBook);
	}
	catch (const EParseError & exc)
	{
		m_DisplayName = tr("%1 (Cannot parse file: %2)")
			.arg(m_VcfFileNameBase)
			.arg(QString::fromStdString(exc.m_Message));
	}
	catch (const EException &)
	{
		m_DisplayName = tr("%1 (Cannot parse file)").arg(m_VcfFileNameBase);
		return;
	}
}





void DeviceVcfFile::stop()
{
	// Nothing needed
}





bool DeviceVcfFile::isOnline() const
{
	return !m_VcfFileName.isEmpty();
}





bool DeviceVcfFile::load(const QJsonObject & a_Config)
{
	m_VcfFileName = a_Config["fileName"].toString();

	// Strip away the path:
	QFileInfo fi(m_VcfFileName);
	m_VcfFileNameBase = fi.fileName();
	m_DisplayName = m_VcfFileNameBase;

	return true;
}





QJsonObject DeviceVcfFile::save() const
{
	QJsonObject res;
	res["fileName"] = m_VcfFileName;
	return res;
}





{'fraction_non_alphanumeric': 0.14545454545454545, 'fraction_numerical': 0.002797202797202797, 'mean_word_length': 4.587890625, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5151259', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1087, 'n_words': 208}