--- src/accountreg.ui~	2007-10-14 18:00:51 +0400
+++ src/accountreg.ui	2008-01-30 23:25:10 +0300
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>384</width>
-    <height>339</height>
+    <height>400</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -77,6 +77,13 @@
             </property>
            </widget>
           </item>
+          <item row="3" column="0" colspan="2" >
+           <widget class="QPushButton" name="pb_fill" >
+            <property name="text" >
+             <string>Fill servers list</string>
+            </property>
+           </widget>
+          </item>
          </layout>
         </widget>
        </item>
--- src/accountregdlg.h~	2007-10-14 18:00:51 +0400
+++ src/accountregdlg.h	2008-01-31 02:50:06 +0300
@@ -23,6 +23,8 @@
 
 #include <QDialog>
 #include <QString>
+#include <QMenu>
+#include <QSignalMapper>
 
 #include "profiles.h"
 #include "xmpp_jid.h"
@@ -57,6 +59,9 @@ public:
 	UserAccount::SSLFlag ssl() const { return ssl_; }
 	int proxy() const { return proxy_; }
 
+signals:
+	void customServersSelected(const QString&);
+
 public slots:
 	void done(int);
 
@@ -68,6 +73,8 @@ protected:
 	void block();
 	void unblock();
 
+	void loadCustomServers(QMenu*);
+
 protected slots:
 	void hostToggled(bool);
 	void sslActivated(int);
@@ -76,6 +83,8 @@ protected slots:
 	void selectServer();
 	void serverListReceived(const QStringList&);
 	void serverListError(const QString&);
+	void fillCustomServers(const QString&);
+	void serverSelected(const QString&);
 
 	void client_handshaken();
 	void client_error();
@@ -83,6 +92,7 @@ protected slots:
 	void getFields_finished();
 	void setFields_finished();
 
+
 private:
 	Ui::AccountReg ui_;
 	QScrollArea* fields_container_;
@@ -92,6 +102,17 @@ private:
 	ServerListQuerier *serverlist_querier_;
 	MiniClient *client_;
 	bool isOld_;
+	struct CustomServerInfo
+	{
+	    QString section;
+	    QString name;
+	    QString hostname;
+	    QString ip;
+	    QString port;
+	};
+	QList<CustomServerInfo> serverlist_custom_;
+	QString serverlist_custom_section_;
+	QSignalMapper *servers_fill_from_menu_mapper;
 
 	// Account settings
 	XMPP::Jid jid_, server_;
--- src/accountregdlg.cpp~	2007-10-14 18:00:51 +0400
+++ src/accountregdlg.cpp	2008-02-25 17:09:33 +0300
@@ -21,6 +21,7 @@
 #include <QtCrypto>
 #include <QMessageBox>
 #include <QScrollArea>
+#include <QSettings>
 
 #include "accountregdlg.h"
 #include "proxy.h"
@@ -48,11 +49,22 @@ AccountRegDlg::AccountRegDlg(ProxyManage
 	port_ = 5222;
 	
 	// Server select button
-	connect(ui_.le_server,SIGNAL(popup()),SLOT(selectServer()));
+	connect(ui_.le_server,SIGNAL(activated(const QString&)),SLOT(serverSelected(const QString&)));
 	serverlist_querier_ = new ServerListQuerier(this);
 	connect(serverlist_querier_,SIGNAL(listReceived(const QStringList&)),SLOT(serverListReceived(const QStringList&)));
 	connect(serverlist_querier_,SIGNAL(error(const QString&)),SLOT(serverListError(const QString&)));
 
+	// Server list fill button
+	servers_fill_from_menu_mapper = new QSignalMapper(this);
+	QMenu *servers_fill_from_menu = new QMenu(ui_.pb_fill);
+	servers_fill_from_menu->addAction(tr("from Internet"), this, SLOT(selectServer()))->setData(QString(""));
+	loadCustomServers(servers_fill_from_menu);
+	ui_.pb_fill->setMenu(servers_fill_from_menu);
+	connect(servers_fill_from_menu_mapper, SIGNAL(mapped(const QString &)),
+	    this, SIGNAL(customServersSelected(const QString &)));
+	connect(this, SIGNAL(customServersSelected(const QString &)),
+	    this, SLOT(fillCustomServers(const QString &)));
+
 	// Manual Host/Port
 	ui_.le_host->setEnabled(false);
 	ui_.lb_host->setEnabled(false);
@@ -150,13 +162,95 @@ void AccountRegDlg::hostToggled(bool on)
 
 void AccountRegDlg::selectServer()
 {
-	if (ui_.le_server->count() == 0) {
+	if (ui_.le_server->count() == 0 || !serverlist_custom_section_.isEmpty()) {
 		ui_.busy->start();
 		block();
+		serverlist_custom_section_ = "";
 		serverlist_querier_->getList();
 	}
 }
 
+void AccountRegDlg::loadCustomServers(QMenu *menu)
+{
+    CustomServerInfo srvinfo;
+
+#ifdef Q_WS_X11
+    QString confdir = "/etc/psi";
+#else
+    QString confdir = ApplicationInfo::resourcesDir();
+#endif
+
+    QString config = confdir + "/custom_servers_list";
+    if( !QFile::exists(config) )
+	return;
+
+    QSettings custom_servers_conf(config, QSettings::IniFormat);
+    QStringList groups = custom_servers_conf.childGroups();
+    QString last_section;
+    QStringListIterator it(groups);
+    while( it.hasNext() )
+    {
+	QString group = it.next();
+	custom_servers_conf.beginGroup(group);
+	srvinfo.section  = QString::fromUtf8(custom_servers_conf.value("section").toByteArray());
+	srvinfo.name     = QString::fromUtf8(custom_servers_conf.value("name").toByteArray());
+	srvinfo.hostname = QString::fromUtf8(custom_servers_conf.value("hostname").toByteArray());
+	srvinfo.ip       = QString::fromLatin1(custom_servers_conf.value("ip").toByteArray());
+	srvinfo.port     = QString::fromLatin1(custom_servers_conf.value("port").toByteArray());
+	custom_servers_conf.endGroup();
+
+	if( srvinfo.section.isEmpty() || srvinfo.name.isEmpty() || srvinfo.hostname.isEmpty() )
+	    continue;
+
+	serverlist_custom_.append(srvinfo);
+	if( last_section != srvinfo.section )
+	{
+	    last_section = srvinfo.section;
+	    QAction *a = menu->addAction(tr("from %1").arg(srvinfo.section));
+	    connect(a, SIGNAL(triggered()), servers_fill_from_menu_mapper, SLOT(map()));
+	    servers_fill_from_menu_mapper->setMapping(a, srvinfo.section);
+	}
+    }
+}
+
+void AccountRegDlg::fillCustomServers(const QString &section)
+{
+    serverlist_custom_section_ = section;
+    QStringList lst;
+    CustomServerInfo srvinfo;
+    foreach(srvinfo, serverlist_custom_)
+    {
+	if( srvinfo.section == section )
+	    lst.append(srvinfo.name);
+    }
+    serverListReceived(lst);
+}
+
+void AccountRegDlg::serverSelected(const QString &name)
+{
+    if( serverlist_custom_section_.isEmpty() )
+    {
+	ui_.ck_host->setChecked(false);
+	ui_.le_host->setText("");
+	ui_.le_port->setText("5222");
+    }
+    else
+    {
+	CustomServerInfo srvinfo;
+	foreach(srvinfo, serverlist_custom_)
+	{
+	    if( srvinfo.section == serverlist_custom_section_ && srvinfo.name == name )
+	    {
+		ui_.le_server->setEditText(srvinfo.hostname);
+		ui_.ck_host->setChecked(!srvinfo.ip.isEmpty());
+		ui_.le_host->setText(srvinfo.ip);
+		ui_.le_port->setText(srvinfo.port.isEmpty()?"5222":srvinfo.port);
+		break;
+	    }
+	}
+    }
+}
+
 void AccountRegDlg::serverListReceived(const QStringList& list)
 {
 	ui_.busy->stop();
