std::string ResourceURIFactory::makeUniqueURI(const std::string &uri)
{
    std::lock_guard<std::mutex> lock(m_lock);
    if (isUnique(uri))
    {
        updateUri(uri);
        return uri;
    }
    std::ostringstream os;
    os << uri;
    if (!uri.empty() && '/' != uri[uri.length() - 1])
        os << '/';
    os << m_id++;
    updateUri(os.str());
    return os.str();
}
ConnectionDialog::ConnectionDialog (QWidget *parent)
	: QDialog (parent)
{
	fSettings settings;

	uriLabel = new QLabel (tr ("IRC URI"), this);
	uriLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);

	uriEdit = new QLineEdit (this);
	connect (uriEdit, SIGNAL (textChanged (QString)), this, SLOT (uriChanged (QString)));

	serverLabel = new QLabel (tr ("IRC server"), this);
	serverLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);

	serverEdit = new QComboBox (this);
	serverEdit->setEditable (true);
	serverEdit->addItems(settings.value("Connection/Servers", QStringList()).toStringList());
	serverEdit->setCurrentIndex (-1);
	connect (serverEdit, SIGNAL (editTextChanged (QString)), this, SLOT (serverChanged ()));
	connect (serverEdit, SIGNAL (editTextChanged (QString)), this, SLOT (updateUri ()));

	roomLabel = new QLabel (tr ("Room"), this);
	roomLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);

	roomEdit = new QComboBox (this);
	roomEdit->setEditable (true);
	roomEdit->setEnabled (false);
	connect (roomEdit, SIGNAL (editTextChanged (QString)), this, SLOT (updateUri ()));

	nickLabel = new QLabel (tr ("Nick"), this);
	nickLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);

	nickEdit = new QComboBox (this);
	nickEdit->setEditable (true);
	nickEdit->setEnabled (false);

	encodingLabel = new QLabel (tr ("Encoding"), this);
	encodingLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);

	encodingEdit = new QComboBox (this);
	encodingEdit->setEditable (false);

	{
		QList<int> textCodecs = QTextCodec::availableMibs();

		for (QList<int>::iterator it = textCodecs.begin (), end = textCodecs.end (); it != end; it++) {
			encodingEdit->addItem (QTextCodec::codecForMib(*it)->name());
		}
		encodingEdit->setCurrentIndex (encodingEdit->findText ("UTF-8"));
	}

	QGridLayout *layout = new QGridLayout ();
	layout->addWidget (uriLabel, 0, 0);
	layout->addWidget (uriEdit, 0, 1);
	layout->addWidget (serverLabel, 1, 0);
	layout->addWidget (serverEdit, 1, 1);
	layout->addWidget (roomLabel, 2, 0);
	layout->addWidget (roomEdit, 2, 1);
	layout->addWidget (nickLabel, 3, 0);
	layout->addWidget (nickEdit, 3, 1);
	layout->addWidget (encodingLabel, 4, 0);
	layout->addWidget (encodingEdit, 4, 1);

	QDialogButtonBox *buttonBox = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
				Qt::Horizontal,
				this);
	connect (buttonBox, SIGNAL (accepted ()), this, SLOT (saveAndAccept ()));
	connect (buttonBox, SIGNAL (rejected ()), this, SLOT (reject ()));

	QVBoxLayout *mainLayout = new QVBoxLayout ();
	mainLayout->addLayout (layout);
	mainLayout->addWidget (buttonBox);

	setLayout (mainLayout);

	serverEdit->setCurrentIndex(settings.value("Connection/LastServer", -1).toInt ());
}