/* * This file is a part of VyQChat. * * Copyright (C) 2002-2004 Pawel Stolowski * * VyQChat is free software; you can redestribute it and/or modify it * under terms of GNU General Public License by Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY. See GPL for more details. */ #include "global.h" #include "settings.h" #include #include #include #include #include #include #include #include Settings::Settings() /*{{{*/ { cfg.beginGroup("/vyqchat"); }/*}}}*/ Settings::~Settings()/*{{{*/ { cfg.endGroup(); }/*}}}*/ bool Settings::getDefaults()/*{{{*/ { QString datapath(DATADIR); bool status = false; def_topic = "no topic"; def_sound = Sound::PCSpeaker; def_playcmd = "/usr/bin/play"; // // get hostname char tmp[255]; gethostname(tmp, 254); def_hostname = QString(tmp); // // get username char *login = getenv("LOGNAME"); def_nick = QString(login); // // get eth0 parameters def_broadcast = "255.255.255.255"; def_mcastgrp = "227.0.0.2"; def_ip = "127.0.0.1"; def_port = 8167; struct ifconf ifc; int sockfd = socket(AF_INET, SOCK_DGRAM, 0); ifc.ifc_req = new ifreq [16]; ifc.ifc_len = 16*sizeof(struct ifreq); if (ioctl(sockfd, SIOCGIFCONF, &ifc)==0) { status = true; const int num = ifc.ifc_len/sizeof(struct ifreq); struct ifreq *req = ifc.ifc_req; for (int i=0; i(cfg.readNumEntry("/Method", NET_BROADCAST)); //use broadcast by default refresh = cfg.readNumEntry("/Refresh", 300); cfg.endGroup(); cfg.beginGroup("/Misc"); systray = cfg.readBoolEntry("/Systray", true); encoding = cfg.readEntry("/Encoding", ""); useutf = cfg.readBoolEntry("/UTF", true); hide_channels = cfg.readBoolEntry("/HideChannels", false); popup = cfg.readBoolEntry("/Popup", true); nopopup_dnd = cfg.readBoolEntry("/NoPopupDND", true); cfg.endGroup(); cfg.beginGroup("/General"); version = cfg.readEntry("/Version", "0", &ok); if (!ok) cfg.writeEntry("/Version", VYQCHAT_VERSION); uuid = cfg.readEntry("/UUID", QString::null, &ok); if (!ok) cfg.writeEntry("/UUID", uuid.asString()); regexp_on = cfg.readBoolEntry("/RegExpOn", false); toolbar_on = cfg.readBoolEntry("/ToolbarOn", true); userslist_on = cfg.readBoolEntry("/UsersListOn", true); nickcombo_on = cfg.readBoolEntry("/NickComboOn", true); confirm_exit = cfg.readBoolEntry("/ConfirmExit", true); topic = cfg.readEntry("/Topic", def_topic); keep_status = cfg.readBoolEntry("/KeepStatus", true); status = cfg.readNumEntry("/Status", STATUS_NORMAL); cfg.endGroup(); cfg.beginGroup("/Sound"); sound = static_cast(cfg.readNumEntry("/sound", def_sound)); playcmd = cfg.readEntry("/PlayCommand", def_playcmd); cfg.endGroup(); cfg.beginGroup("/Wavs"); for (int i=0; i(i)), ""); cfg.endGroup(); cfg.beginGroup("/WavFlags"); for (int i=0; i(i)), false); cfg.endGroup(); cfg.beginGroup("/Scripts"); for (int i=0; i(i)), QString::null); cfg.endGroup(); cfg.beginGroup("/ScriptFlags"); for (int i=0; i(i)), false); cfg.endGroup(); cfg.beginGroup("/Window"); x = cfg.readNumEntry("/x", -1); y = cfg.readNumEntry("/y", -1); width = cfg.readNumEntry("/Width", 480); height = cfg.readNumEntry("/Height", 360); listwidth = cfg.readNumEntry("/ListWidth", 120); winvisible = cfg.readBoolEntry("/StartVisible", true); cfg.endGroup(); cfg.beginGroup("/Look"); icontheme = cfg.readEntry("/IconTheme", "default"); cfg.endGroup(); return true; }/*}}}*/ const QString Settings::getEventKey(VyEvent s) const/*{{{*/ { switch (s) { case EventChatline: return QString("/Chatline"); break; case EventMessage: return QString("/Message"); break; case EventJoin: return QString("/Join"); break; case EventLeave: return QString("/Leave"); break; case EventBeep: return QString("/Beep"); break; case EventRegexpMatch: return QString("/RegexpMatch"); break; default: break; } return QString::null; }/*}}}*/ void Settings::setSampleFileName(VyEvent s, const QString &f)/*{{{*/ { const QString key = getEventKey(s); if (!key.isEmpty()) { cfg.beginGroup("/Wavs"); cfg.writeEntry(key, snd[s] = f); cfg.endGroup(); } }/*}}}*/ void Settings::setSampleEnabled(VyEvent s, bool f)/*{{{*/ { const QString key = getEventKey(s); if (!key.isEmpty()) { cfg.beginGroup("/WavFlags"); cfg.writeEntry(key, sndp[s] = f); cfg.endGroup(); } }/*}}}*/ void Settings::setScriptFileName(VyEvent e, const QString &f)/*{{{*/ { const QString key = getEventKey(e); if (!key.isEmpty()) { cfg.beginGroup("/Scripts"); cfg.writeEntry(key, scr[e] = f); cfg.endGroup(); } }/*}}}*/ void Settings::setScriptEnabled(VyEvent e, bool f)/*{{{*/ { const QString key = getEventKey(e); if (!key.isEmpty()) { cfg.beginGroup("/ScriptFlags"); cfg.writeEntry(key, scrf[e] = f); cfg.endGroup(); } }/*}}}*/