Changeset 5984 for branches/newosd

Show
Ignore:
Timestamp:
01/03/08 06:20:24 (11 months ago)
Author:
eugene
Message:

Made values be read in from config file.

Location:
branches/newosd/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/newosd/src/conf.cpp

    r5981 r5984  
    66#include <licq_file.h> 
    77 
    8 Conf::Conf() 
     8Conf::~Conf() 
    99{ 
    10   font = NULL; 
    11  
    12   posHorizontal = COORDINATE_MINIMUM; 
    13   posVertical = COORDINATE_MINIMUM; 
    14   offsetHorizontal = 0; 
    15   offsetVertical = 0; 
    16   marginHorizontal = 0; 
    17   marginVertical = 0; 
    18   wrapWidth = 0; 
    19   maxLines = 0; 
    20  
    21   backColor = NULL; 
    22   backOpacity = 0; 
    23  
    24   shadowColor = "black"; 
    25   shadowOpacity = 255; 
    26   shadowOffset = 2; 
    27  
    28   textColor = "yellow"; 
    29   textControlColor = "gray"; 
    30   textOpacity = 255; 
    31  
    32   markSecure = true; 
    33  
    34   fadeIn = 150; 
    35   fadeFull = 3000; 
    36   fadeOut = 150; 
    37   delayPerChar = 0; 
    38   quietTimeout = 4; 
    39  
    40   wait = true; 
    41   mouseActive = true; 
    42  
    43   logonLogoff = GROUP_TYPE_ALL; 
    44   statusChange = GROUP_TYPE_ALL; 
    45   autoResponse = GROUP_TYPE_ALL; 
    46   showMessage = GROUP_TYPE_ALL; 
    47   notifyOnly = false; 
    48   ownerModes = NULL; 
    49   ownerModesMsg = NULL; 
     10  cleanup(); 
    5011} 
    5112 
    5213void Conf::loadConfig() 
    5314{ 
    54 /*  std::string file = BASE_DIR; 
     15  std::string file = BASE_DIR; 
    5516  file += "licq_newosd.ini"; 
     17 
     18  cleanup(); 
    5619 
    5720  CIniFile conf(INI_FxWARN); 
    5821  if (!conf.LoadFile(file.c_str())) 
    5922  { 
    60     setDefaults(); 
    61     return; 
    62   }*/ 
     23    conf.SetFlags(INI_FxALLOWxCREATE); 
     24    if (!conf.ReloadFile()) 
     25      return; 
     26    conf.CreateSection("Appearance"); 
     27    conf.CreateSection("Colouring"); 
     28    conf.CreateSection("Geometry"); 
     29    conf.CreateSection("Timing"); 
     30    conf.CreateSection("Behavior"); 
     31    conf.CreateSection("Filtering"); 
     32    conf.FlushFile(); 
     33  } 
     34 
     35  char buf[MAX_LINE_LEN] = ""; 
     36 
     37#define COPY(key, dst, def); \ 
     38  conf.ReadStr((key), buf, (def)); \ 
     39  if (buf[0] != '\0') \ 
     40  { \ 
     41    (dst) = strdup(buf); \ 
     42    buf[0] = '\0'; \ 
     43  } 
     44 
     45  if (conf.SetSection("Appearance")) 
     46  { 
     47    COPY("Font", font, ""); 
     48 
     49    conf.ReadBool("MarkSecureMessages", markSecure, true); 
     50  } 
     51 
     52  if (conf.SetSection("Colouring")) 
     53  { 
     54    COPY("Background", backColor, ""); 
     55    COPY("Message", textColor, "yellow"); 
     56    COPY("Control", textControlColor, "gray"); 
     57    COPY("Shadow", shadowColor, "black"); 
     58 
     59    conf.ReadNum("BackOpacity", backOpacity, 0); 
     60    conf.ReadNum("TextOpacity", textOpacity, 255); 
     61    conf.ReadNum("ShadowOpacity", shadowOpacity, 255); 
     62 
     63    if (backOpacity > 255) 
     64      backOpacity %= 255; 
     65    if (textOpacity > 255) 
     66      textOpacity %= 255; 
     67    if (shadowOpacity > 255) 
     68      shadowOpacity %= 255; 
     69  } 
     70 
     71  if (conf.SetSection("Geometry")) 
     72  { 
     73    conf.ReadNum("HPosition", reinterpret_cast<unsigned short&>(posHorizontal), 0); 
     74    conf.ReadNum("VPosition", reinterpret_cast<unsigned short&>(posVertical), 0); 
     75 
     76    if (posHorizontal > COORDINATE_MAXIMUM) 
     77      posHorizontal = COORDINATE_MINIMUM; 
     78    if (posVertical > COORDINATE_MAXIMUM) 
     79      posVertical = COORDINATE_MINIMUM; 
     80 
     81    conf.ReadNum("HOffset", offsetHorizontal, 0); 
     82    conf.ReadNum("VOffset", offsetVertical, 0); 
     83 
     84    conf.ReadNum("HMargin", marginHorizontal, 0); 
     85    conf.ReadNum("VMargin", marginVertical, 0); 
     86 
     87    conf.ReadNum("ShadowOffset", shadowOffset, 2); 
     88    conf.ReadNum("Width", wrapWidth, 0); 
     89    conf.ReadNum("Lines", maxLines, 0); 
     90  } 
     91 
     92  if (conf.SetSection("Timing")) 
     93  { 
     94    conf.ReadNum("FadeIn", fadeIn, 150); 
     95    conf.ReadNum("FadeFull", fadeFull, 3000); 
     96    conf.ReadNum("FadeOut", fadeOut, 150); 
     97 
     98    conf.ReadNum("DelayPerCharacter", delayPerChar, 0); 
     99  } 
     100 
     101  if (conf.SetSection("Behavior")) 
     102  { 
     103    conf.ReadBool("Wait", wait, true); 
     104    conf.ReadBool("MouseActive", mouseActive, true); 
     105    conf.ReadNum("QuietTimeout", quietTimeout, 0); 
     106  } 
     107 
     108  if (conf.SetSection("Filtering")) 
     109  { 
     110    conf.ReadNum("ShowLogonLogoff", 
     111        reinterpret_cast<unsigned short&>(logonLogoff), 2); 
     112    conf.ReadNum("ShowStatusChange", 
     113        reinterpret_cast<unsigned short&>(statusChange), 2); 
     114    conf.ReadNum("ShowAutoResponseCheck", 
     115        reinterpret_cast<unsigned short&>(autoResponse), 2); 
     116    conf.ReadNum("ShowMessages", 
     117        reinterpret_cast<unsigned short&>(showMessage), 2); 
     118 
     119    if (logonLogoff > GROUP_TYPE_ALL) 
     120      logonLogoff = GROUP_TYPE_ALL; 
     121    if (statusChange > GROUP_TYPE_ALL) 
     122      statusChange = GROUP_TYPE_ALL; 
     123    if (autoResponse > GROUP_TYPE_ALL) 
     124      autoResponse = GROUP_TYPE_ALL; 
     125    if (showMessage > GROUP_TYPE_ALL) 
     126      showMessage = GROUP_TYPE_ALL; 
     127 
     128    conf.ReadBool("ShowMessagesNotification", notifyOnly, false); 
     129    COPY("ShowInModes", ownerModes, ""); 
     130    COPY("ShowMsgsInModes", ownerModesMsg, ""); 
     131  } 
     132 
     133#undef COPY 
     134} 
     135 
     136void Conf::cleanup() 
     137{ 
     138#define CLEAN(str); \ 
     139  if ((str) != NULL) \ 
     140  { \ 
     141    free((str)); \ 
     142    (str) = NULL; \ 
     143  } 
     144 
     145  CLEAN(font); 
     146  CLEAN(backColor); 
     147  CLEAN(shadowColor); 
     148  CLEAN(textColor); 
     149  CLEAN(textControlColor); 
     150  CLEAN(ownerModes); 
     151  CLEAN(ownerModesMsg); 
     152#undef CLEAN 
    63153} 
    64154 
  • branches/newosd/src/conf.h

    r5981 r5984  
    1414class Conf 
    1515{ 
    16 public: 
    17   Conf(); 
     16private: 
     17  ~Conf(); 
    1818 
    19 private: 
    2019  void loadConfig(); 
     20  void cleanup(); 
    2121 
    2222  char* font; 
     
    2626  short offsetHorizontal; 
    2727  short offsetVertical; 
    28   guint8 marginHorizontal; 
    29   guint8 marginVertical; 
     28  unsigned short marginHorizontal; 
     29  unsigned short marginVertical; 
    3030  short wrapWidth; 
    3131  unsigned short maxLines; 
    3232 
    3333  char* backColor; 
    34   guint8 backOpacity; 
     34  unsigned short backOpacity; 
    3535 
    3636  char* shadowColor; 
    37   guint8 shadowOpacity; 
     37  unsigned short shadowOpacity; 
    3838  short shadowOffset; 
    3939 
    4040  char* textColor; 
    4141  char* textControlColor; 
    42   guint8 textOpacity; 
     42  unsigned short textOpacity; 
    4343 
    4444  bool markSecure; 
     
    4848  unsigned short fadeOut; 
    4949  unsigned short delayPerChar; 
    50   guint8 quietTimeout; 
     50  unsigned short quietTimeout; 
    5151 
    5252  bool wait; 
  • branches/newosd/src/iface.cpp

    r5982 r5984  
    2727  } 
    2828  FOR_EACH_OWNER_END; 
     29 
     30  string init = "Licq newosd plugin is initialized."; 
     31  displayLayout(init, false); 
    2932} 
    3033