<commit_before>=begin
/***************************************************************************
 *   Copyright (C) 2005,2006,2007 by <NAME>                          *
 *   <EMAIL>                                                     *
 *                                                                         *
 *   Translated to Ruby by <NAME>                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with self program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 ***************************************************************************/
=end

require 'plasma_applet'
require 'analog_clock_config.rb'
require 'calendar'

module PlasmaRubyAnalogClock

class Clock < Plasma::Containment

  slots :moveSecondHand, :configAccepted, 
        'showCalendar(QGraphicsSceneMouseEvent *)',
        'dataUpdated(QString, Plasma::DataEngine::Data)'

  def initialize(parent, args)
    super
    KDE::Global.locale.insertCatalog("libplasmaclock")

    setHasConfigurationInterface(true)
    resize(125, 125)
    setAspectRatioMode(Plasma::Square)

    @theme = Plasma::Svg.new(self)
    @theme.imagePath = "widgets/clock"
    @theme.containsMultipleImages = false
    @theme.resize(size())

    @timezone = ""
    @showTimeString = false
    @showSecondHand = false
    @ui = Ui::AnalogClockConfig.new
    @calendarUi = Ui::Calendar.new

    @lastTimeSeen = Qt::Time.new
    @calendar = 0
    @time = Qt::Time.new
  end

  def init
    cg = config()
    @showTimeString = cg.readEntry("showTimeString", false)
    @showSecondHand = cg.readEntry("showSecondHand", false)
    @fancyHands = cg.readEntry("fancyHands", false)
    @timezone = cg.readEntry("timezone", "Local")

    connectToEngine()
  end

  def connectToEngine
    # Use 'dataEngine("ruby-time")' for the ruby version of the engine
    timeEngine = dataEngine("time")
    if @showSecondHand
        timeEngine.connectSource(@timezone, self, 500)
    else 
        timeEngine.connectSource(@timezone, self, 6000, Plasma::AlignToMinute)
    end
  end

  def constraintsEvent(constraints)
    if constraints.to_i & Plasma::FormFactorConstraint.to_i
      setBackgroundHints(NoBackground)
    end
  end

  def shape
    path = Qt::PainterPath.new
    path.addEllipse(boundingRect().adjusted(-2, -2, 2, 2))
    return path
  end

  def dataUpdated(source, data)
    @time = data["Time"].toTime()
return
    if @time.minute == @lastTimeSeen.minute &&
      @time.second == @lastTimeSeen.second
      # avoid unnecessary repaints
      return
    end

    if @secondHandUpdateTimer
        @secondHandUpdateTimer.stop
    end

    @lastTimeSeen = @time
    update()
  end<commit_msg>* Enable data updates for the clock now it doesn't crash anymore<commit_after>=begin
/***************************************************************************
 *   Copyright (C) 2005,2006,2007 by <NAME>                          *
 *   <EMAIL>                                                     *
 *                                                                         *
 *   Translated to Ruby by <NAME>                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with self program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 ***************************************************************************/
=end

require 'plasma_applet'
require 'analog_clock_config.rb'
require 'calendar'

module PlasmaRubyAnalogClock

class Clock < Plasma::Containment

  slots :moveSecondHand, :configAccepted, 
        'showCalendar(QGraphicsSceneMouseEvent *)',
        'dataUpdated(QString, Plasma::DataEngine::Data)'

  def initialize(parent, args)
    super
    KDE::Global.locale.insertCatalog("libplasmaclock")

    setHasConfigurationInterface(true)
    resize(125, 125)
    setAspectRatioMode(Plasma::Square)

    @theme = Plasma::Svg.new(self)
    @theme.imagePath = "widgets/clock"
    @theme.containsMultipleImages = false
    @theme.resize(size())

    @timezone = ""
    @showTimeString = false
    @showSecondHand = false
    @ui = Ui::AnalogClockConfig.new
    @calendarUi = Ui::Calendar.new

    @lastTimeSeen = Qt::Time.new
    @calendar = 0
    @time = Qt::Time.new
  end

  def init
    cg = config()
    @showTimeString = cg.readEntry("showTimeString", false)
    @showSecondHand = cg.readEntry("showSecondHand", false)
    @fancyHands = cg.readEntry("fancyHands", false)
    @timezone = cg.readEntry("timezone", "Local")

    connectToEngine()
  end

  def connectToEngine
    # Use 'dataEngine("ruby-time")' for the ruby version of the engine
    timeEngine = dataEngine("time")
    if @showSecondHand
        timeEngine.connectSource(@timezone, self, 500)
    else 
        timeEngine.connectSource(@timezone, self, 6000, Plasma::AlignToMinute)
    end
  end

  def constraintsEvent(constraints)
    if constraints.to_i & Plasma::FormFactorConstraint.to_i
      setBackgroundHints(NoBackground)
    end
  end

  def shape
    path = Qt::PainterPath.new
    path.addEllipse(boundingRect().adjusted(-2, -2, 2, 2))
    return path
  end

  def dataUpdated(source, data)
    @time = data["Time"].toTime()
    if @time.minute == @lastTimeSeen.minute &&
      @time.second == @lastTimeSeen.second
      # avoid unnecessary repaints
      return
    end

    if @secondHandUpdateTimer
        @secondHandUpdateTimer.stop
    end

    @lastTimeSeen = @time
    update()
  end
{'fraction_non_alphanumeric': 0.12255296326092786, 'fraction_numerical': 0.011263073209975865, 'mean_word_length': 1.9658051689860836, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6336319', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1878, 'n_words': 531}