Changeset 5981 for branches/newosd

Show
Ignore:
Timestamp:
01/03/08 00:56:18 (11 months ago)
Author:
eugene
Message:

Major update. Converted almost everything to take config parameters.

Location:
branches/newosd/src
Files:
2 added
4 modified

Legend:

Unmodified
Added
Removed
  • branches/newosd/src/CMakeLists.txt

    r5856 r5981  
    33set(SRCS 
    44    plugin.cpp 
     5    conf.cpp 
    56    iface.cpp) 
    67 
  • branches/newosd/src/iface.cpp

    r5979 r5981  
    44#include <licq_translate.h> 
    55 
     6#include "conf.h" 
     7 
    68Iface::Iface() 
    79{ 
    810  aosd = aosd_new(); 
    911  aosd_set_transparency(aosd, TRANSPARENCY_COMPOSITE); 
    10   aosd_set_hide_upon_mouse_event(aosd, True); 
    1112  aosd_set_renderer(aosd, aosd_text_renderer, &trd); 
    1213  aosd_set_names(aosd, "OSD Plugin", "Licq"); 
    1314 
     15  g_type_init(); 
    1416  memset(&trd, 0, sizeof(TextRenderData)); 
    15  
    16   g_type_init(); 
    17  
    1817  trd.lay = pango_layout_new_aosd(); 
    19  
    20   trd.geom.x_offset = 10; 
    21   trd.geom.y_offset = 10; 
    22  
    23   trd.shadow.x_offset = 2; 
    24   trd.shadow.y_offset = 2; 
    25   trd.shadow.color = "black"; 
    26   trd.shadow.opacity = 192; 
    27  
    28   trd.fore.opacity = 255; 
    29  
    30   pango_layout_set_font_aosd(trd.lay, "Times New Roman Bold 24"); 
    31  
    32   int max_width; 
    33   aosd_get_screen_size(aosd, &max_width, NULL); 
    34   max_width -= 2 * trd.geom.x_offset + trd.shadow.x_offset + 80; 
    35   if (max_width > 0) 
    36     pango_layout_set_width(trd.lay, max_width * PANGO_SCALE); 
    3718  pango_layout_set_wrap(trd.lay, PANGO_WRAP_WORD_CHAR); 
     19 
     20  conf = new Conf(); 
     21 
     22  updateTextRenderData(); 
     23 
     24  FOR_EACH_OWNER_START(LOCK_R) 
     25  { 
     26    ppidTimers[pOwner->PPID()] = time(NULL); 
     27  } 
     28  FOR_EACH_OWNER_END; 
    3829} 
    3930 
    4031Iface::~Iface() 
    4132{ 
     33  delete conf; 
     34  ppidTimers.clear(); 
    4235  aosd_destroy(aosd); 
    4336  pango_layout_unref_aosd(trd.lay); 
     
    4740{ 
    4841  string msg = ""; 
    49   bool message = false; 
     42  bool control = true; 
    5043 
    5144  switch (sig->Signal()) 
     
    5346    case SIGNAL_UPDATExUSER: 
    5447    { 
    55       if (!checkDisabledTimer() || 
    56           !checkOwner(sig)) 
     48      if (filterSignal(sig)) 
    5749        break; 
    5850 
    59       ICQUser* u = checkUser(sig->Id(), sig->PPID()); 
     51      ICQUser* u = gUserManager.FetchUser(sig->Id(), sig->PPID(), LOCK_R); 
    6052      if (u == NULL) 
    6153        break; 
     
    8678 
    8779          { 
    88             CUserEvent* ue = u->EventPeekId(sig->Argument()); 
    89             if (ue == NULL) 
    90               break; 
    91             if (u->Secure()) // TODO config check 
    92               msg += " (S)"; 
    93             msg += ": "; 
    94             char* trans = gTranslator.ToUnicode(const_cast<char*>(ue->Text()), 
    95                 u->UserEncoding()); 
    96             msg += trans; 
    97             delete[] trans; 
    98             message = true; 
     80            control = false; 
     81            if (conf->notifyOnly) 
     82            { 
     83              msg = "Message from "; 
     84              msg += u->GetAlias(); 
     85              if (conf->markSecure && u->Secure()) 
     86                msg += " [secured]"; 
     87              msg += "."; 
     88            } 
     89            else 
     90            { 
     91              CUserEvent* ue = u->EventPeekId(sig->Argument()); 
     92              if (ue == NULL) 
     93                break; 
     94              if (conf->markSecure && u->Secure()) 
     95                msg += " (S)"; 
     96              msg += ": "; 
     97              char* trans = gTranslator.ToUnicode(const_cast<char*>(ue->Text()), 
     98                  u->UserEncoding()); 
     99              msg += trans; 
     100              delete[] trans; 
     101            } 
    99102          } 
    100103          break; 
     
    110113 
    111114    case SIGNAL_LOGON: 
    112       break; 
    113  
    114115    case SIGNAL_LOGOFF: 
     116      ppidTimers[sig->PPID()] = time(NULL) + conf->quietTimeout; 
    115117      break; 
    116118 
     
    120122 
    121123  if (!msg.empty()) 
    122     displayLayout(msg, message); 
    123 } 
    124  
    125 ICQUser* Iface::checkUser(char* id, unsigned long ppid) 
    126 { 
    127   if (id == NULL) 
    128     return NULL; 
    129  
    130   ICQUser* u = gUserManager.FetchUser(id, ppid, LOCK_R); 
    131  
     124    displayLayout(msg, control); 
     125} 
     126 
     127void Iface::updateTextRenderData() 
     128{ 
     129  conf->loadConfig(); 
     130 
     131  aosd_set_hide_upon_mouse_event(aosd, conf->mouseActive); 
     132  pango_layout_set_font_aosd(trd.lay, conf->font); 
     133 
     134  trd.geom.x_offset = conf->marginHorizontal; 
     135  trd.geom.y_offset = conf->marginVertical; 
     136 
     137  trd.back.color = conf->backColor; 
     138  trd.back.opacity = conf->backOpacity; 
     139 
     140  trd.shadow.x_offset = conf->shadowOffset; 
     141  trd.shadow.y_offset = conf->shadowOffset; 
     142  trd.shadow.color = conf->shadowColor; 
     143  trd.shadow.opacity = conf->shadowOpacity; 
     144 
     145  trd.fore.opacity = conf->textOpacity; 
     146 
     147  int width = aosd_text_get_screen_wrap_width(aosd, &trd); 
     148  if (conf->wrapWidth == 0 || width < 0) 
     149    pango_layout_set_width(trd.lay, -1); 
     150  else 
     151    pango_layout_set_width(trd.lay, 
     152        (width > conf->wrapWidth ? conf->wrapWidth : width) * PANGO_SCALE); 
     153} 
     154 
     155bool Iface::filterSignal(CICQSignal* sig) 
     156{ 
     157  if (ppidTimers[sig->PPID()] > time(NULL)) 
     158    return true; 
     159 
     160  bool ret = false; 
     161 
     162  ICQUser* u = gUserManager.FetchUser(sig->Id(), sig->PPID(), LOCK_R); 
    132163  if (u == NULL) 
    133     return NULL; 
     164    return true; 
    134165 
    135166  if (u->IgnoreList()) 
    136   { 
    137     gUserManager.DropUser(u); 
    138     return NULL; 
    139   } 
    140  
    141   return u; 
    142 } 
    143  
    144 bool Iface::checkOwner(CICQSignal* sig) 
    145 { 
     167    ret = true; 
     168 
     169  gUserManager.DropUser(u); 
     170 
     171  if (ret) 
     172    return true; 
     173 
    146174  ICQOwner* o = gUserManager.FetchOwner(sig->PPID(), LOCK_R); 
    147  
    148175  if (o == NULL) 
    149     return false; 
    150  
    151   bool ret = true; 
     176    return true; 
    152177 
    153178  do 
     
    155180    // TODO status check 
    156181 
     182    // Don't let owner messages (e.g. auth-reqs) be filtered 
    157183    if (sig->Signal() == SIGNAL_UPDATExUSER && 
    158184        sig->SubSignal() == USER_EVENTS && 
     
    162188    if (strcmp(sig->Id(), o->IdString()) == 0) 
    163189    { 
    164       ret = false; 
     190      ret = true; 
    165191      break; 
    166192    } 
    167  
    168193  } while (false); 
    169194 
    170   gUserManager.DropOwner(sig->PPID()); 
     195  gUserManager.DropOwner(o->PPID()); 
     196 
    171197  return ret; 
    172198} 
    173199 
    174 bool Iface::checkDisabledTimer() 
    175 { 
    176   return true; 
    177 } 
    178  
    179 void Iface::displayLayout(string& msg, bool message) 
     200void Iface::displayLayout(string& msg, bool control) 
    180201{ 
    181202  pango_layout_set_text(trd.lay, const_cast<char*>(msg.c_str()), -1); 
    182203 
    183   trd.fore.color = const_cast<char*>(message ? "green" : "gray"); 
     204  trd.fore.color = control ? conf->textControlColor : conf->textColor; 
    184205 
    185206  unsigned width, height; 
    186207 
    187   pango_layout_get_size_aosd(trd.lay, &width, &height, &trd.lbearing); 
     208  aosd_text_get_size(&trd, &width, &height); 
    188209 
    189210  aosd_set_position_with_offset(aosd, 
    190       COORDINATE_MINIMUM, COORDINATE_MAXIMUM, 
    191       width + 2 * trd.geom.x_offset + trd.shadow.x_offset, 
    192       height + 2 * trd.geom.y_offset + trd.shadow.y_offset, 
    193       80, -80); 
    194  
    195   aosd_flash(aosd, 0, 3000, 150); 
     211      conf->posHorizontal, conf->posVertical, 
     212      width, height, conf->offsetHorizontal, conf->offsetVertical); 
     213 
     214  aosd_flash(aosd, conf->fadeIn, 
     215      conf->fadeFull + msg.size() * conf->delayPerChar, conf->fadeOut); 
    196216} 
    197217 
  • branches/newosd/src/iface.h

    r5978 r5981  
    33 
    44#include <string> 
     5#include <map> 
     6#include <time.h> 
    57 
    6 #include <libaosd/aosd.h> 
    7 #include <libaosd/aosd-text.h> 
     8#include <aosd.h> 
     9#include <aosd-text.h> 
    810#undef Status 
    911 
    1012class CICQSignal; 
    1113class ICQUser; 
     14 
     15class Conf; 
    1216 
    1317class Iface 
     
    1822 
    1923  void processSignal(CICQSignal* sig); 
     24  void updateTextRenderData(); 
    2025 
    2126private: 
    2227  Aosd* aosd; 
    2328  TextRenderData trd; 
     29  Conf* conf; 
     30  std::map<unsigned long, time_t> ppidTimers; 
    2431 
    25   ICQUser* checkUser(char* id, unsigned long ppid); 
    26   bool checkOwner(CICQSignal* sig); 
    27   bool checkDisabledTimer(); 
     32  bool filterSignal(CICQSignal* sig); 
    2833 
    29   const char* setLayoutTag(ICQUser* u); 
    30   void displayLayout(std::string& msg, bool message); 
     34  void displayLayout(std::string& msg, bool control); 
    3135}; 
    3236 
  • branches/newosd/src/plugin.cpp

    r5980 r5981  
    108108 
    109109      case '1': 
     110        iface->updateTextRenderData(); 
    110111        blocked = false; 
    111112        break;