Ticket #4116: 4116-fixes-v1.patch

File 4116-fixes-v1.patch, 8.7 KB (added by danielk, 16 years ago)

Backported to fixes..

  • libs/libmythtv/osdtypes.cpp

     
    658658
    659659OSDTypeText::OSDTypeText(const QString &name, TTFFont *font,
    660660                         const QString &text, QRect displayrect,
    661                          float wmult, float hmult)
    662            : OSDType(name)
    663 {
    664     m_message = text;
    665     m_default_msg = text;
    666     m_font = font;
     661                         float wmult, float hmult) :
     662    OSDType(name),
     663    m_lock(true),
     664    m_displaysize(displayrect),
     665    m_screensize(displayrect),
     666    m_unbiasedsize(unbias(m_screensize, wmult, hmult)),
     667    m_message(QDeepCopy<QString>(text)),
     668    m_default_msg(QDeepCopy<QString>(text)),
    667669
    668     m_altfont = NULL;
    669    
    670     m_displaysize = displayrect;
    671     m_screensize = displayrect;
    672     m_multiline = false;
    673     m_centered = false;
    674     m_right = false;
    675     m_usingalt = false;
     670    m_font(font),
     671    m_altfont(NULL),
    676672
    677     m_selected  = false;
    678     m_button    = false;
    679     m_entrynum  = -1;
    680     m_cursorpos = 0;
     673    m_centered(false),
     674    m_right(false),
    681675
    682     m_scroller = false;
    683     m_scrollx = m_scrolly = 0;
    684     m_scrollinit = false;
     676    m_multiline(false),
     677    m_usingalt(false),
    685678
    686     m_linespacing = 1.5;
     679    m_selected(false),
     680    m_button(false),
     681    m_entrynum(-1),
     682    m_cursorpos(0),
    687683
    688     m_unbiasedsize = unbias(m_screensize, wmult, hmult);
     684    m_scroller(false),
     685    m_scrollx(0),
     686    m_scrolly(0),
    689687
    690     m_draw_info_str = "";
    691     m_draw_info_len = 0;
     688    m_scrollinit(false),
     689
     690    m_linespacing(1.5f),
     691
     692    m_draw_info_str(""),
     693    m_draw_info_len(0)
     694{
    692695}
    693696
    694 OSDTypeText::OSDTypeText(const OSDTypeText &other)
    695            : OSDType(other.m_name)
     697OSDTypeText::OSDTypeText(const OSDTypeText &other) :
     698    OSDType(other.m_name),
     699    m_draw_info_str(""),
     700    m_draw_info_len(0)
    696701{
    697     m_message = other.m_message;
    698     m_default_msg = other.m_default_msg;
     702    QMutexLocker locker(&other.m_lock);
     703
     704    m_displaysize = other.m_displaysize;
     705    m_screensize = other.m_screensize;
     706    m_unbiasedsize = other.m_unbiasedsize;
     707
     708    m_message = QDeepCopy<QString>(other.m_message);
     709    m_default_msg = QDeepCopy<QString>(other.m_default_msg);
     710
    699711    m_font = other.m_font;
    700 
    701712    m_altfont = other.m_altfont;
    702713
    703     m_displaysize = other.m_displaysize;
    704     m_screensize = other.m_screensize;
    705     m_multiline = other.m_multiline;
    706714    m_centered = other.m_centered;
    707715    m_right = other.m_right;
    708     m_usingalt = other.m_usingalt;
    709    
    710     m_selected = other.m_selected;
    711     m_button   = other.m_button;
    712     m_entrynum = other.m_entrynum;
    713     m_cursorpos = other.m_cursorpos;
    714  
     716
     717    m_multiline = other.m_multiline;
     718    m_usingalt = other.m_usingalt;
     719
     720    m_selected = other.m_selected;
     721    m_button   = other.m_button;
     722    m_entrynum = other.m_entrynum;
     723    m_cursorpos = other.m_cursorpos;
     724
    715725    m_scroller = other.m_scroller;
    716726    m_scrollx = other.m_scrollx;
    717727    m_scrolly = other.m_scrolly;
     728
    718729    m_scrollinit = other.m_scrollinit;
    719730
    720731    m_linespacing = other.m_linespacing;
    721 
    722     m_unbiasedsize = other.m_unbiasedsize;
    723 
    724     m_draw_info_str = "";
    725     m_draw_info_len = 0;
    726732}
    727733
    728734OSDTypeText::~OSDTypeText()
     
    731737
    732738void OSDTypeText::SetAltFont(TTFFont *font)
    733739{
     740    QMutexLocker locker(&m_lock);
    734741    m_altfont = font;
    735742}
    736743
    737744void OSDTypeText::SetText(const QString &text)
    738745{
    739     m_message = text;
     746    QMutexLocker locker(&m_lock);
     747    m_message = QDeepCopy<QString>(text);
    740748    m_cursorpos = text.length();
    741749    m_scrollinit = false;
    742750}
    743751
     752QString OSDTypeText::GetText(void) const
     753{
     754    QMutexLocker locker(&m_lock);
     755    return QDeepCopy<QString>(m_message);
     756}
     757
    744758void OSDTypeText::SetDefaultText(const QString &text)
    745759{
    746     m_message = text;
    747     m_default_msg = text;
     760    QMutexLocker locker(&m_lock);
     761    m_message = QDeepCopy<QString>(text);
     762    m_default_msg = QDeepCopy<QString>(text);
    748763    m_scrollinit = false;
    749764}
     765 
     766QString OSDTypeText::GetDefaultText(void) const
     767{
     768    QMutexLocker locker(&m_lock);
     769    return QDeepCopy<QString>(m_default_msg);
     770}
    750771
     772void OSDTypeText::SetMultiLine(bool multi)
     773{
     774    QMutexLocker locker(&m_lock);
     775    m_multiline = multi;
     776}
     777
     778void OSDTypeText::SetCentered(bool docenter)
     779{
     780    QMutexLocker locker(&m_lock);
     781    m_centered = docenter;
     782}
     783
     784void OSDTypeText::SetRightJustified(bool right)
     785{
     786    QMutexLocker locker(&m_lock);
     787    m_right = right;
     788}
     789
     790void OSDTypeText::SetScrolling(int x, int y)
     791{
     792    QMutexLocker locker(&m_lock);
     793    m_scroller = true;
     794    m_scrollx = x;
     795    m_scrolly = y;
     796}
     797
     798void OSDTypeText::SetLineSpacing(float linespacing)
     799{
     800    QMutexLocker locker(&m_lock);
     801    m_linespacing = linespacing;
     802}
     803
    751804void OSDTypeText::Reinit(float wmult, float hmult)
    752805{
     806    QMutexLocker locker(&m_lock);
    753807    m_displaysize = m_screensize = bias(m_unbiasedsize, wmult, hmult);
    754808}
    755809
    756810void OSDTypeText::Draw(OSDSurface *surface, int fade, int maxfade, int xoff,
    757811                       int yoff)
    758812{
     813    QMutexLocker locker(&m_lock);
     814
     815    // initialize regular expressions once, this is a very slow operation
     816    static QMutex regexp_lock;
     817    static QRegExp br("%BR%");
     818    static QRegExp nl("\n");
     819
    759820    int textlength = 0;
    760821
    761822    if (m_message == QString::null)
     
    773834
    774835    if (m_multiline)
    775836    {
    776         QString tmp_msg = m_message;
    777         tmp_msg.replace(QRegExp("%BR%"), "\n");
    778         tmp_msg.replace(QRegExp("\n")," \n ");
     837        QString tmp_msg = QDeepCopy<QString>(m_message);
     838        regexp_lock.lock();
     839        tmp_msg.replace(br, "\n");
     840        tmp_msg.replace(nl," \n ");
     841        regexp_lock.unlock();
    779842
    780843        QStringList wordlist = QStringList::split(" ", tmp_msg);
    781844        int length = 0;
     
    902965                                   const QString &text, int fade, int maxfade,
    903966                                   int xoff, int yoff, bool double_size)
    904967{
     968    QMutexLocker locker(&m_lock);
     969
    905970    if (m_draw_info_str != text)
    906971    {
    907972        m_draw_info_str = QDeepCopy<QString>(text);
     
    10151080                             const QString &text, int fade, int maxfade,
    10161081                             int xoff, int yoff, bool doubl)
    10171082{
     1083    QMutexLocker locker(&m_lock);
     1084
    10181085    if (m_centered || m_right)
    10191086    {
    10201087        int textlength = 0;
     
    10671134
    10681135bool OSDTypeText::MoveCursor(int dir)
    10691136{
     1137    QMutexLocker locker(&m_lock);
     1138
    10701139    if (!IsEntry() || IsButton())
    10711140        return false;
    10721141
     
    10771146
    10781147bool OSDTypeText::Delete(int dir)
    10791148{
     1149    QMutexLocker locker(&m_lock);
     1150
    10801151    if (!IsEntry() || IsButton())
    10811152        return false;
    10821153
     
    10991170
    11001171void OSDTypeText::InsertCharacter(QChar ch)
    11011172{
     1173    QMutexLocker locker(&m_lock);
     1174
    11021175    if (!IsEntry() || IsButton())
    11031176        return;
    11041177
  • libs/libmythtv/osdtypes.h

     
    202202    void SetUseAlt(bool usealt) { m_usingalt = usealt; }
    203203
    204204    void SetText(const QString &text);
    205     QString GetText() { return m_message; }
     205    QString GetText(void) const;
    206206
    207207    void SetDefaultText(const QString &text);
    208     QString GetDefaultText() { return m_default_msg; }
     208    QString GetDefaultText(void) const;
    209209
    210     void SetMultiLine(bool multi) { m_multiline = multi; }
    211     bool GetMultiLine() { return m_multiline; }
     210    void SetMultiLine(bool multi);
     211    bool GetMultiLine(void) const { return m_multiline; }
    212212
    213     void SetCentered(bool docenter) { m_centered = docenter; }
    214     bool GetCentered() { return m_centered; }
     213    void SetCentered(bool docenter);
     214    bool GetCentered(void) const { return m_centered; }
    215215
    216     void SetRightJustified(bool right) { m_right = right; }
    217     bool GetRightJustified() { return m_right; }
     216    void SetRightJustified(bool right);
     217    bool GetRightJustified(void) const { return m_right; }
    218218
    219     void SetScrolling(int x, int y) { m_scroller = true; m_scrollx = x;
    220                                       m_scrolly = y; }
     219    void SetScrolling(int x, int y);
    221220
    222     void SetLineSpacing(float linespacing) { m_linespacing = linespacing; }
    223     float GetLineSpacing() { return m_linespacing; }
     221    void SetLineSpacing(float linespacing);
     222    float GetLineSpacing(void) const { return m_linespacing; }
    224223
    225224    void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
    226225    bool MoveCursor(int dir);
     
    245244                          const QString &text, int fade, int maxfade,
    246245                          int xoff, int yoff, bool double_size = false);
    247246
     247    mutable QMutex m_lock;
     248
    248249    QRect m_displaysize;
    249250    QRect m_screensize;
    250251    QRect m_unbiasedsize;