Пример #1
0
void TimeZoneActivity::loadTimeZones() {
  std::vector<UIKit::ModelViewItem *> _item_list;

  foreach(const QByteArray id, QTimeZone::availableTimeZoneIds()) {
    QString l_time_zone_lable_str = QString(id);
    l_time_zone_lable_str +=
        " " + QTimeZone(id).displayName(QDateTime::currentDateTime(),
                                        QTimeZone::OffsetName);

    UIKit::Label *lTimeZoneLabelPtr =
        new UIKit::Label(m_priv_ptr->m_timezone_browser_ptr);
    UIKit::ModelViewItem *l_item = new UIKit::ModelViewItem();

    l_item->set_data("label", l_time_zone_lable_str);
    l_item->set_data("zone_id", id);
    l_item->on_activated([&](UIKit::ModelViewItem *a_item) {
      if (a_item) {
        m_priv_ptr->m_result_data["timezone"] =
            a_item->data("label").toString();
        m_priv_ptr->m_result_data["zone_id"] =
            a_item->data("zone_id").toByteArray();
        notify_done();
      }
    });

    l_item->set_view(lTimeZoneLabelPtr);
    l_item->on_view_removed([&] (UIKit::ModelViewItem *a_item) {
      if (a_item && a_item->view()) {
          UIKit::Widget *view = a_item->view();
          if (view)
            delete view;
      }
    });
    l_item->on_filter([&](const UIKit::Widget *a_view,
                          const QString &a_keyword) {
      const UIKit::Label *_lbl_widget =
          dynamic_cast<const UIKit::Label *>(a_view);

      if (_lbl_widget) {
        if (_lbl_widget->label().toLower().contains(a_keyword.toLower())) {
          return 1;
        }
      }

      return 0;
    });

    lTimeZoneLabelPtr->set_alignment(Qt::AlignLeft);

    lTimeZoneLabelPtr->setMinimumSize(
        m_priv_ptr->m_timezone_browser_ptr->geometry().width(), 32);
    lTimeZoneLabelPtr->set_size(
        QSizeF(m_priv_ptr->m_timezone_browser_ptr->boundingRect().width(), 32));
    lTimeZoneLabelPtr->set_label(l_time_zone_lable_str);
    _item_list.push_back(l_item);
  }
/**
 * e_data_cal_view_notify_done:
 * @query: A query object.
 * @error: Query completion error, if any.
 *
 * Notifies all query listeners of the completion of the query, including a
 * status code.
 */
void
e_data_cal_view_notify_done (EDataCalView *view, const GError *error)
{
	EDataCalViewPrivate *priv;

	g_return_if_fail (view && E_IS_DATA_CAL_VIEW (view));
	priv = view->priv;

	if (!priv->started || priv->stopped)
		return;

	g_mutex_lock (priv->pending_mutex);

	priv->done = TRUE;

	notify_done (view, error);

	g_mutex_unlock (priv->pending_mutex);
}
Пример #3
0
void date_dialog::create_window(const QRectF &window_geometry,
                                const QString &window_title,
                                const QPointF &window_pos) {
  priv->m_activity_window = new cherry_kit::window();
  priv->m_activity_window->setGeometry(window_geometry);
  priv->m_activity_window->set_window_title(window_title);

  cherry_kit::fixed_layout *view =
      new cherry_kit::fixed_layout(priv->m_activity_window);

  view->set_content_margin(5, 5, 5, 5);
  view->set_geometry(0, 0, window_geometry.width(), window_geometry.height());

  view->add_rows(2);
  view->add_segments(0, 1);
  view->add_segments(1, 3);

  view->set_row_height(0, "90%");
  view->set_row_height(1, "10%");

  cherry_kit::widget_properties_t prop;
  prop["label"] = "Apply";

  priv->m_cal_widget = dynamic_cast<cherry_kit::calendar_view *>(
      view->add_widget(0, 0, "calendar", prop, [=]() {}));

  priv->m_done_btn = dynamic_cast<cherry_kit::button *>(
      view->add_widget(1, 1, "button", prop, [=]() {}));

  priv->m_activity_window->set_window_content(view->viewport());

  priv->m_done_btn->on_click([this]() {
    notify_calendar_value();
    notify_done();
  });
}
Пример #4
0
/*
 * Sleep in select() until we can do something.  This will initialize the
 * select masks.  Upon return, the masks will indicate which descriptors
 * have data or can accept data.  Optionally, a maximum time can be specified
 * for the duration of the wait (0 = infinite).
 */
static void
wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
    u_int *nallocp, u_int64_t max_time_milliseconds)
{
	struct timeval tv, *tvp;
	int ret;
	time_t minwait_secs = 0;
	int client_alive_scheduled = 0;
	int program_alive_scheduled = 0;

	/* Allocate and update select() masks for channel descriptors. */
	channel_prepare_select(readsetp, writesetp, maxfdp, nallocp,
	    &minwait_secs, 0);

	if (minwait_secs != 0)
		max_time_milliseconds = MIN(max_time_milliseconds,
		    (u_int)minwait_secs * 1000);

	/*
	 * if using client_alive, set the max timeout accordingly,
	 * and indicate that this particular timeout was for client
	 * alive by setting the client_alive_scheduled flag.
	 *
	 * this could be randomized somewhat to make traffic
	 * analysis more difficult, but we're not doing it yet.
	 */
	if (compat20 &&
	    max_time_milliseconds == 0 && options.client_alive_interval) {
		client_alive_scheduled = 1;
		max_time_milliseconds =
		    (u_int64_t)options.client_alive_interval * 1000;
	}

	if (compat20) {
#if 0
		/* wrong: bad condition XXX */
		if (channel_not_very_much_buffered_data())
#endif
		FD_SET(connection_in, *readsetp);
	} else {
		/*
		 * Read packets from the client unless we have too much
		 * buffered stdin or channel data.
		 */
		if (buffer_len(&stdin_buffer) < buffer_high &&
		    channel_not_very_much_buffered_data())
			FD_SET(connection_in, *readsetp);
		/*
		 * If there is not too much data already buffered going to
		 * the client, try to get some more data from the program.
		 */
		if (packet_not_very_much_data_to_write()) {
			program_alive_scheduled = child_terminated;
			if (!fdout_eof)
				FD_SET(fdout, *readsetp);
			if (!fderr_eof)
				FD_SET(fderr, *readsetp);
		}
		/*
		 * If we have buffered data, try to write some of that data
		 * to the program.
		 */
		if (fdin != -1 && buffer_len(&stdin_buffer) > 0)
			FD_SET(fdin, *writesetp);
	}
	notify_prepare(*readsetp);

	/*
	 * If we have buffered packet data going to the client, mark that
	 * descriptor.
	 */
	if (packet_have_data_to_write())
		FD_SET(connection_out, *writesetp);

	/*
	 * If child has terminated and there is enough buffer space to read
	 * from it, then read as much as is available and exit.
	 */
	if (child_terminated && packet_not_very_much_data_to_write())
		if (max_time_milliseconds == 0 || client_alive_scheduled)
			max_time_milliseconds = 100;

	if (max_time_milliseconds == 0)
		tvp = NULL;
	else {
		tv.tv_sec = max_time_milliseconds / 1000;
		tv.tv_usec = 1000 * (max_time_milliseconds % 1000);
		tvp = &tv;
	}

	/* Wait for something to happen, or the timeout to expire. */
	ret = select((*maxfdp)+1, *readsetp, *writesetp, NULL, tvp);

	if (ret == -1) {
		memset(*readsetp, 0, *nallocp);
		memset(*writesetp, 0, *nallocp);
		if (errno != EINTR)
			error("select: %.100s", strerror(errno));
	} else {
		if (ret == 0 && client_alive_scheduled)
			client_alive_check();
		if (!compat20 && program_alive_scheduled && fdin_is_tty) {
			if (!fdout_eof)
				FD_SET(fdout, *readsetp);
			if (!fderr_eof)
				FD_SET(fderr, *readsetp);
		}
	}

	notify_done(*readsetp);
}
Пример #5
0
void led_thread(void)
{
    msg_t msg;
    int ret;

    color_hsv_t hsv_0;
    color_hsv_t hsv_1;
    color_rgb_t rgb;

    float step_h = 1.0f;
    float step_s = 0.02f;
    float step_v = 0.02f;
    int step = 0;

    int state = 1;
    int limit = 1;
    color_rgb_t *sequ = cd_sequ;

    rgbled_t led;

    /* initialize RGB-LED */
    rgbled_init(&led, PWM_0, 0, 1, 2);

    while (1) {
        /* see if something has come up */
        if (state == limit) {
            notify_done();
            ++state;
        }
        if (state >= limit) {
            ret = msg_receive(&msg);
        } else {
            ret = msg_try_receive(&msg);
        }

        /* if message was receive, act on it */
        if (ret == 1) {
            printf("led: got message %i\n", msg.type);
            if (msg.type != last_cmd) {
                switch (msg.type) {
                    case MSG_GAME_START:
                        puts("led: starting game");
                        sequ = cd_sequ;
                        state = 1;
                        limit = GAME_LED_COUNTDOWN_LEN;
                        last_cmd = msg.type;
                        break;
                    case MSG_GAME_SCORE:
                        printf("led: displaying score: %i\n", (unsigned int)msg.content.value);
                        if (PLAYER == msg.content.value) {
                            puts("led: WIN sequence");
                            sequ = win_sequ;
                            limit = GAME_LED_WIN_LEN;
                        }
                        else if (msg.content.value == GAME_STATE_DRAW) {
                            puts("led: DRAW sequence");
                            sequ = draw_sequ;
                            limit = GAME_LED_DRAW_LEN;
                        }
                        else {
                            puts("led: LOSE sequence");
                            sequ = lose_sequ;
                            limit = GAME_LED_LOSE_LEN;
                        }
                        state = 1;
                        last_cmd = msg.type;
                        break;
                }
            }
        }

        if (state < limit) {
            /* update color */
            if (step == 0) {
                printf("led: setting color fr 0x%02x 0x%02x 0x%02x\n",
                       sequ[state - 1].r, sequ[state - 1].g, sequ[state - 1].b);
                printf("led: setting color to 0x%02x 0x%02x 0x%02x\n",
                       sequ[state].r, sequ[state].g, sequ[state].b);

                color_rgb2hsv(&sequ[state - 1], &hsv_0);
                color_rgb2hsv(&sequ[state ], &hsv_1);

                step_h = (hsv_0.h - hsv_1.h) / STEPS;
                step_s = (hsv_0.s - hsv_1.s) / STEPS;
                step_v = (hsv_0.v - hsv_1.v) / STEPS;
                printf("led: steps are h+= %i s+= %i v+= %i\n", (int)(step_h * 100),(int)(step_s * 100),
                                                                (int)(step_v * 100));
            }

            /* set color */
            color_hsv2rgb(&hsv_0, &rgb);
            rgbled_set(&led, &rgb);
            ++step;
            hsv_0.h += step_h;
            hsv_0.s += step_s;
            hsv_0.v += step_v;

            /* check if transition is finished */
            if (step == STEPS) {
                step = 0;
                ++state;
            }
        }

        /* wait for next step */
        vtimer_usleep(PAUSE);
    }
}