Esempio n. 1
0
void WidgetChatBubble::add_filerecv(Toxmm::EventFileRecv file) {
    auto msg_time = Glib::DateTime::create_now_utc();

    // remove seconds
    msg_time = Glib::DateTime::create_utc(msg_time.get_year(),
                                          msg_time.get_month(),
                                          msg_time.get_day_of_month(),
                                          msg_time.get_hour(),
                                          msg_time.get_minute(),
                                          0);

    bool display_time = true;

    if (m_last_timestamp != 0) {
        auto old_time = Glib::DateTime::create_now_utc(m_last_timestamp);
        // remove seconds
        old_time = Glib::DateTime::create_utc(old_time.get_year(),
                                              old_time.get_month(),
                                              old_time.get_day_of_month(),
                                              old_time.get_hour(),
                                              old_time.get_minute(),
                                              0);
        // check
        display_time = !(msg_time.compare(old_time) == 0);
    }

    // create a new row
    auto msg  = Gtk::manage(WidgetChatFileRecv::create(observable(), file));
    auto time = Gtk::manage(new Gtk::Label());
    m_last_timestamp = msg_time.to_unix();

    // get local time
    msg_time = Glib::DateTime::create_now_local(m_last_timestamp);

    time->set_text(msg_time.format("%R"));

    // add to grid
    if (m_side == RIGHT) {
        rows.emplace_back(m_grid, m_row_count, *msg, *time);
    } else {
        rows.emplace_back(m_grid, m_row_count, *time, *msg);
    }
    m_row_count += 1;

    // styling
    time->set_halign(Gtk::ALIGN_CENTER);
    time->set_valign(Gtk::ALIGN_START);
    time->get_style_context()->add_class("bubble_chat_line_time");

    msg->set_halign(Gtk::ALIGN_START);
    msg->set_valign(Gtk::ALIGN_CENTER);

    msg->show_all();
    time->show_all();
    time->set_no_show_all();
    if (!display_time) {
        time->hide();
    }
}
Esempio n. 2
0
        InputIterator get(
            iter_type b, iter_type e,
            std::ios_base& iob,
            std::ios_base::iostate& err,
            std::tm* tm,
            char fmt, char) const
        {
            err = std::ios_base::goodbit;
            const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(iob.getloc());

            switch (fmt)
            {
            case 'a':
            case 'A':
              {
                std::tm tm2;
                std::memset(&tm2, 0, sizeof(std::tm));
                that_.get_weekday(b, e, iob, err, &tm2);
                //tm->tm_wday = tm2.tm_wday;
              }
              break;
            case 'b':
            case 'B':
            case 'h':
              {
                std::tm tm2;
                std::memset(&tm2, 0, sizeof(std::tm));
                that_.get_monthname(b, e, iob, err, &tm2);
                //tm->tm_mon = tm2.tm_mon;
              }
              break;
//            case 'c':
//              {
//                const string_type& fm = c();
//                b = get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
//              }
//              break;
            case 'd':
            case 'e':
              get_day(tm->tm_mday, b, e, err, ct);
              break;
            case 'D':
              {
                const char_type fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'F':
              {
                const char_type fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'H':
              get_hour(tm->tm_hour, b, e, err, ct);
              break;
            case 'I':
              get_12_hour(tm->tm_hour, b, e, err, ct);
              break;
            case 'j':
              get_day_year_num(tm->tm_yday, b, e, err, ct);
              break;
            case 'm':
              get_month(tm->tm_mon, b, e, err, ct);
              break;
            case 'M':
              get_minute(tm->tm_min, b, e, err, ct);
              break;
            case 'n':
            case 't':
              get_white_space(b, e, err, ct);
              break;
//            case 'p':
//              get_am_pm(tm->tm_hour, b, e, err, ct);
//              break;
            case 'r':
              {
                const char_type fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'R':
              {
                const char_type fm[] = {'%', 'H', ':', '%', 'M'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'S':
              get_second(tm->tm_sec, b, e, err, ct);
              break;
            case 'T':
              {
                const char_type fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'w':
              {
                get_weekday(tm->tm_wday, b, e, err, ct);
              }
              break;
            case 'x':
              return that_.get_date(b, e, iob, err, tm);
//            case 'X':
//              return that_.get_time(b, e, iob, err, tm);
//              {
//                const string_type& fm = X();
//                b = that_.get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
//              }
//              break;
//            case 'y':
//              get_year(tm->tm_year, b, e, err, ct);
                break;
            case 'Y':
              get_year4(tm->tm_year, b, e, err, ct);
              break;
            case '%':
              get_percent(b, e, err, ct);
              break;
            default:
                err |= std::ios_base::failbit;
            }
            return b;
        }
Esempio n. 3
0
void WidgetChatBubble::add_message(Line new_line) {
    auto msg_time = Glib::DateTime::create_now_utc(new_line.timestamp);
    // remove seconds
    msg_time = Glib::DateTime::create_utc(msg_time.get_year(),
                                          msg_time.get_month(),
                                          msg_time.get_day_of_month(),
                                          msg_time.get_hour(),
                                          msg_time.get_minute(),
                                          0);

    bool display_time = true;

    if (m_last_timestamp != 0) {
        auto old_time = Glib::DateTime::create_now_utc(m_last_timestamp);
        // remove seconds
        old_time = Glib::DateTime::create_utc(old_time.get_year(),
                                              old_time.get_month(),
                                              old_time.get_day_of_month(),
                                              old_time.get_hour(),
                                              old_time.get_minute(),
                                              0);
        // check
        display_time = !(msg_time.compare(old_time) == 0);
    }

    // create a new row
    auto msg  = Gtk::manage(new WidgetChatLabel());
    auto time = Gtk::manage(new Gtk::Label());
    m_last_timestamp = new_line.timestamp;

    // get local time
    msg_time = Glib::DateTime::create_now_local(m_last_timestamp);

    time->set_text(msg_time.format("%R"));
    msg->set_text(new_line.message);

    // add to grid
    if (m_side == RIGHT) {
        rows.emplace_back(m_grid, m_row_count, *msg, *time);
    } else {
        rows.emplace_back(m_grid, m_row_count, *time, *msg);
    }
    if (new_line.wait_for_receipt) {
        rows.back().set_class("message_pending");
        //callback !
        auto nr = new_line.nr;
        auto receipt = new_line.receipt;
        auto index = rows.size() - 1;
        rows.back().tox_callback = observer_add([this, index, nr, receipt](const ToxEvent &ev) {
            //wait for receipt
            if (ev.type() == typeid(Toxmm::EventReadReceipt)) {
                auto& row = rows[index];
                auto data = ev.get<Toxmm::EventReadReceipt>();
                if (data.nr == nr) {
                    if (data.receipt > receipt) {
                        //message failed !
                        row.set_class("message_failed");
                        row.tox_callback.reset();
                    } else if (data.receipt == receipt) {
                        //message got !
                        row.set_class("message_receipt");
                        row.tox_callback.reset();
                    }
                }
            }
        });
    }
    if (new_line.error) {
        rows.back().set_class("message_failed");
    }
    for(size_t i = 0; i < rows.size(); ++i) {
        rows[i].set_class(i == 0, i == rows.size()-1);
    }
    m_row_count += 1;

    // styling
    time->set_halign(Gtk::ALIGN_CENTER);
    time->set_valign(Gtk::ALIGN_START);
    time->get_style_context()->add_class("bubble_chat_line_time");

    msg->set_halign(Gtk::ALIGN_START);
    msg->set_valign(Gtk::ALIGN_CENTER);

    msg->show_all();
    time->show_all();
    time->set_no_show_all();
    if (!display_time) {
        time->hide();
    }
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
void t_display_rysuj_siatke_czas (T_Display *w)
{
		int wys ;
		char ctmp [20] ;
		
		wys = w->canvas->allocation.height ;
		
		// kolor siatki i opisow
		GdkGC *gc = gdk_gc_new (GTK_LAYOUT(w->canvas)->bin_window);
		GdkColor color ;
		color.red = 0;
		color.green = 40000;
		color.blue = 0;		
		gdk_gc_set_rgb_fg_color(gc,&color) ;
		
		time_t hours = w->last_time - w->last_time % w->time_step ;
		
		int dzialka_godz = w->time_step / 3600 ;
		
		//printf ("%d %d %d\n",hours, dzialka_godz, w->last_time % w->time_step) ;
		if (w->time_step > 60*60) { // dla dzialki powyzej godziny utrzymac polnoc :)
				hours = full_hour(w->last_time) ;
				while ( ((get_hour(hours) % dzialka_godz) != 0) &&
							 (hours > (w->last_time - w->time_range)) )
				{
						hours -= 3600 ;		// czasami nie pokazuje najpozniejszej godziny dla dzialki 3h
						// pewnie przez jakies dziwne zjawiska z czasem (lata przestepne ?)
				} ;
		} ;
		//printf ("%d\n",hours) ;
		
		int x_hours ;
		PangoLayout *etykieta ;
		int et_szer, et_wys ;
		int label_x, label_y ;
		
		while (hours > (w->last_time - w->time_range))
		{
				x_hours = time_to_pixel_x(hours, w) ;
				
				//snprintf (&(ctmp[0]), 20, "%.2d:%.2d", get_hour(hours), get_minute(hours)) ;
				gen_time_label_string(&(ctmp[0]), 20, hours, w) ;
				etykieta = gtk_widget_create_pango_layout (w->canvas,ctmp);
				
				pango_layout_get_pixel_size (etykieta, &et_szer, &et_wys) ;
				label_x = x_hours-et_szer/2 ;
				label_y = et_wys+LABEL_MARGIN/2 ;
				
				PangoMatrix matrix = PANGO_MATRIX_INIT;
				if (w->x_labels_vert == TRUE) 
				{
						pango_matrix_rotate (&matrix, 90.);
						label_x = x_hours - (et_wys)/2 ;
						label_y = et_szer + LABEL_MARGIN ;
				} ;
				pango_context_set_matrix (pango_layout_get_context(etykieta), &matrix);
				pango_layout_context_changed(etykieta) ;
				
				// rysowanie dzialek i etykiet
				gdk_draw_layout (GTK_LAYOUT(w->canvas)->bin_window, 
												 //w->canvas->style->fg_gc[GTK_WIDGET_STATE (w->canvas)],
												 gc,
												 label_x, wys-label_y - w->legend_height, etykieta) ;
				gdk_draw_line (GTK_LAYOUT(w->canvas)->bin_window,
											 //w->canvas->style->fg_gc[GTK_WIDGET_STATE (w->canvas)],
											 gc,
											 x_hours,wys-w->y_pixel_offset,x_hours,wys-wys) ;
				
				// pogrubienie wybranych dzialek
				if ((get_seconds(hours) == 0) && 
						(get_minute(hours) == 0)  && 
						(get_hour(hours) == 0) )
				{
						gdk_draw_line (GTK_LAYOUT(w->canvas)->bin_window,
													 //w->canvas->style->fg_gc[GTK_WIDGET_STATE (w->canvas)],
													 gc,
													 x_hours+1,wys-w->y_pixel_offset,x_hours+1,wys-wys) ;
				} ;
				
				g_object_unref(etykieta) ;
				
				hours -= w->time_step ;
		} ;
		
		g_object_unref(gc) ;
		
} ;
Esempio n. 5
0
// 0 for no, 1 for yes
int is_in_range(char * start_date_string, char * end_date_string, long * date_column, int * time_column) {
    
    int start_month = get_month(start_date_string);
    int start_day = get_day(start_date_string);
    int start_year = get_year(start_date_string);
    int start_hour = get_hour(start_date_string);
    int start_minute = get_minute(start_date_string);
    
    int end_month = get_month(end_date_string);
    int end_day = get_day(end_date_string);
    int end_year = get_year(end_date_string);
    int end_hour = get_hour(end_date_string);
    int end_minute = get_minute(end_date_string);
    
    int row_year = ((int)*date_column) / 10000;
    int row_month = ((int)*date_column) / 100;
    row_month = row_month % 100;
    int row_day =((int)*date_column) % 100;
    
    if (*time_column > 2359 || *time_column < 0) {
        return -1;
    }
    
    int row_hour = *time_column / 100;
    int row_minute = *time_column % 100;

    if (start_year > end_year) {
        return -1;
    }
    if (start_year == end_year && start_month > end_month) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day > end_day) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day == end_day && start_hour > end_hour) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day == end_day && start_hour == end_hour && start_minute > end_minute) {
        return -1;
    }
    
    // check if measurement was taken after start time, if not return 0
    if (row_year >= start_year) {
        if (row_year == start_year) {
            if (row_month >= start_month) {
                if (row_month == start_month) {
                    if (row_day >= start_day) {
                        if (row_day == start_day) {
                            if (row_hour >= start_hour) {
                                if (row_hour == start_hour) {
                                    if (row_minute >= start_minute) {
                                    } else return 0;
                                }
                            } else return 0;
                        }
                    } else return 0;
                }
            } else return 0;
        }
    } else return 0;
    
    if (row_year <= end_year) {
        if (row_year == end_year) {
            if(row_month <= end_month) {
                if (row_month == end_month) {
                    if (row_day <= end_day) {
                        if (row_day == end_day) {
                            if (row_hour <= end_hour) {
                                if (row_hour == end_hour) {
                                    if (row_minute <= end_minute) {
                                    } else return 0;
                                }
                            } else return 0;
                        }
                    } else return 0;
                }
            } else return 0;
        }
    } else return 0;
    
    return 1;
}
Esempio n. 6
0
int validate_avg_min_or_max(char * query) {
    char * command;
    command = (char *)calloc(11, sizeof(char));
    char * header;
    header = (char *)calloc(17, sizeof(char));
    char * header_word_2;
    header_word_2 = (char *)calloc(4, sizeof(char));
    char * header_word_3;
    header_word_3 = (char *)calloc(2, sizeof(char));
    char * start_date;
    start_date = (char *)calloc(17, sizeof(char));
    char * end_date;
    end_date = (char *)calloc(19, sizeof(char));
    
    // count whitespace in query to determine if header is multiple words
    int query_length = (int)strlen(query);
    int num_spaces = 0;
    for (int i=0; i<query_length; i++) {
        if (query[i] == ' ') {
            num_spaces++;
        }
    }
    if (num_spaces == 5) {
        sscanf(query, "%s %s %s %s %s %s", command, header, header_word_2, header_word_3, start_date, end_date);
        for (int i=0; i<40; i++) {
            if (header[i] == '\0') {
                header[i] = ' ';
                for (int k=0; k<40; k++) {
                    if (header_word_2[k] != '\0') {
                        header[i+k+1] = header_word_2[k];
                    } else {
                        header[i+k+1] = ' ';
                        header[i+k+2] = header_word_3 [0];
                        header[i+k+3] = '\0';
                        break;
                    }
                }
                break;
            }
        }
    } else if (num_spaces == 4) {
        sscanf(query, "%s %s %s %s %s", command, header, header_word_2, start_date, end_date);
        for (int i=0; i<40; i++) {
            if (header[i] == '\0') {
                header[i] = ' ';
                for (int k=0; k<40; k++) {
                    if (header_word_2[k] != '\0') {
                        header[i+k+1] = header_word_2[k];
                    } else {
                        break;
                    }
                }
                break;
            }
        }
    } else {
        sscanf(query, "%s %s %s %s", command, header, start_date, end_date);
    }
    
    // check if <header> is valid. Must contain numerical values only. Must be a string.
    Type_t data_type;
    data_type = column_type(header);
    if (data_type == UNKNOWN || data_type == STRING || data_type == CHAR) {
        printf("ERROR invalid query: %s\nreason: %s is not valid", query, header);
        return 0;
    }
    
    // check if <start date/time> and <end date/time> are valid. Must be mm/dd/yyyy-hh:mm eg: 02/22/1995-22:57
    if (strlen(start_date) != 16 || get_month(start_date) <= 0 || get_month(start_date) > 12 || get_day(start_date) <= 0 || get_day(start_date) > 31 || get_hour(start_date) < 0 || get_hour(start_date) > 23 || get_minute(start_date) < 0 || get_minute(start_date) > 59) {
        printf("ERROR invalid query: %s\nreason: %s is an invalid start date \n", query, start_date);
        return 0;
    }
    if (strlen(end_date) != 16 || get_month(end_date) <= 0 || get_month(end_date) > 12 || get_day(end_date) <= 0 || get_day(end_date) > 31 || get_hour(end_date) < 0 || get_hour(end_date) > 23 || get_minute(end_date) < 0 || get_minute(end_date) > 59) {
        printf("ERROR invalid query: %s\nreason: %s is an invalid end date \n", query, end_date);
        return 0;
    }
    
    return 1;
}