Whoa... the power.. of C

static void
photos_application_actions_update (PhotosApplication *self)
{
PhotosBaseItem *item;
GList *l;
GList *selection;
PhotosLoadState load_state;
PhotosWindowMode mode;
gboolean can_open;
gboolean can_trash;
gboolean enable;
gboolean selection_mode;
const gchar *cancel_accels[] = { "Escape", NULL };
const gchar *null_accels[] = { NULL };
guint n_items = 0;

item = photos_application_get_selection_or_active_item (self);
load_state = photos_item_manager_get_load_state (self->state->item_mngr);
mode = photos_mode_controller_get_window_mode (self->state->mode_cntrlr);
selection = photos_selection_controller_get_selection (self->sel_cntrlr);
selection_mode = photos_utils_get_selection_mode ();

if (selection_mode)
{
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.edit-cancel", null_accels);

switch (mode)
{
case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
case PHOTOS_WINDOW_MODE_COLLECTIONS:
case PHOTOS_WINDOW_MODE_FAVORITES:
case PHOTOS_WINDOW_MODE_OVERVIEW:
case PHOTOS_WINDOW_MODE_SEARCH:
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.import-cancel", null_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.selection-mode", cancel_accels);
break;

case PHOTOS_WINDOW_MODE_IMPORT:
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.import-cancel", cancel_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.selection-mode", null_accels);
break;

case PHOTOS_WINDOW_MODE_NONE:
case PHOTOS_WINDOW_MODE_EDIT:
case PHOTOS_WINDOW_MODE_PREVIEW:
default:
g_assert_not_reached ();
break;
}
}

(cont.)

Attached: Untitled.png (907x831, 74K)

Other urls found in this thread:

gitlab.gnome.org/GNOME/gnome-photos/blob/master/src/photos-application.c
github.com/python/cpython/blob/master/Python/ceval.c#L1115
lwn.net/Articles/444910/
twitter.com/NSFWRedditImage

else
{
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.import-cancel", null_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.selection-mode", null_accels);

switch (mode)
{
case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
case PHOTOS_WINDOW_MODE_COLLECTIONS:
case PHOTOS_WINDOW_MODE_FAVORITES:
case PHOTOS_WINDOW_MODE_IMPORT:
case PHOTOS_WINDOW_MODE_OVERVIEW:
case PHOTOS_WINDOW_MODE_PREVIEW:
case PHOTOS_WINDOW_MODE_SEARCH:
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.edit-cancel", null_accels);
break;

case PHOTOS_WINDOW_MODE_EDIT:
gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.edit-cancel", cancel_accels);
break;

case PHOTOS_WINDOW_MODE_NONE:
default:
g_assert_not_reached ();
break;
}
}

if (mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW
|| mode == PHOTOS_WINDOW_MODE_COLLECTIONS
|| mode == PHOTOS_WINDOW_MODE_FAVORITES
|| mode == PHOTOS_WINDOW_MODE_IMPORT
|| mode == PHOTOS_WINDOW_MODE_OVERVIEW
|| mode == PHOTOS_WINDOW_MODE_SEARCH)
{
PhotosBaseManager *item_mngr_chld;

item_mngr_chld = photos_item_manager_get_for_mode (PHOTOS_ITEM_MANAGER (self->state->item_mngr), mode);
n_items = g_list_model_get_n_items (G_LIST_MODEL (item_mngr_chld));
}

g_simple_action_set_enabled (self->zoom_best_fit_action, FALSE);
g_simple_action_set_enabled (self->zoom_end_action, FALSE);
g_simple_action_set_enabled (self->zoom_out_action, FALSE);

enable = (mode == PHOTOS_WINDOW_MODE_EDIT);
g_simple_action_set_enabled (self->blacks_exposure_action, enable);
g_simple_action_set_enabled (self->contrast_action, enable);
g_simple_action_set_enabled (self->crop_action, enable);

g_simple_action_set_enabled (self->denoise_action, enable);
g_simple_action_set_enabled (self->edit_cancel_action, enable);
g_simple_action_set_enabled (self->edit_done_action, enable);
g_simple_action_set_enabled (self->insta_action, enable);
g_simple_action_set_enabled (self->saturation_action, enable);
g_simple_action_set_enabled (self->shadows_highlights_action, enable);
g_simple_action_set_enabled (self->sharpen_action, enable);

enable = ((mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW
|| mode == PHOTOS_WINDOW_MODE_COLLECTIONS
|| mode == PHOTOS_WINDOW_MODE_FAVORITES
|| mode == PHOTOS_WINDOW_MODE_OVERVIEW
|| mode == PHOTOS_WINDOW_MODE_SEARCH)
&& !selection_mode);
g_simple_action_set_enabled (self->primary_menu_action, enable);

enable = (((mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW
|| mode == PHOTOS_WINDOW_MODE_COLLECTIONS
|| mode == PHOTOS_WINDOW_MODE_FAVORITES
|| mode == PHOTOS_WINDOW_MODE_OVERVIEW)
&& n_items > 0)
|| mode == PHOTOS_WINDOW_MODE_SEARCH);
g_simple_action_set_enabled (self->search_action, enable);
g_simple_action_set_enabled (self->search_match_action, enable);
g_simple_action_set_enabled (self->search_source_action, enable);
g_simple_action_set_enabled (self->search_type_action, enable);

enable = ((mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW
|| mode == PHOTOS_WINDOW_MODE_COLLECTIONS
|| mode == PHOTOS_WINDOW_MODE_FAVORITES
|| mode == PHOTOS_WINDOW_MODE_IMPORT
|| mode == PHOTOS_WINDOW_MODE_OVERVIEW
|| mode == PHOTOS_WINDOW_MODE_SEARCH)
&& n_items > 0);
g_simple_action_set_enabled (self->sel_all_action, enable);
g_simple_action_set_enabled (self->sel_none_action, enable);
g_simple_action_set_enabled (self->selection_mode_action, enable);

THIS IS ALL ONE FUNCTION BY THE WAY

enable = (mode == PHOTOS_WINDOW_MODE_IMPORT);
g_simple_action_set_enabled (self->import_cancel_action, enable);

enable = (mode == PHOTOS_WINDOW_MODE_IMPORT && selection != NULL);
g_simple_action_set_enabled (self->import_action, enable);

enable = (mode == PHOTOS_WINDOW_MODE_PREVIEW);
g_simple_action_set_enabled (self->load_next_action, enable);
g_simple_action_set_enabled (self->load_previous_action, enable);

enable = (load_state == PHOTOS_LOAD_STATE_FINISHED && mode == PHOTOS_WINDOW_MODE_PREVIEW);
g_simple_action_set_enabled (self->gear_action, enable);
g_simple_action_set_enabled (self->set_bg_action, enable);
g_simple_action_set_enabled (self->set_ss_action, enable);
g_simple_action_set_enabled (self->zoom_begin_action, enable);
g_simple_action_set_enabled (self->zoom_in_action, enable);

enable = ((load_state == PHOTOS_LOAD_STATE_FINISHED && mode == PHOTOS_WINDOW_MODE_PREVIEW)
|| (selection_mode && item != NULL));
g_simple_action_set_enabled (self->properties_action, enable);

enable = ((load_state == PHOTOS_LOAD_STATE_FINISHED && mode == PHOTOS_WINDOW_MODE_PREVIEW)
|| (selection_mode && item != NULL && !photos_base_item_is_collection (item)));
g_simple_action_set_enabled (self->print_action, enable);
g_simple_action_set_enabled (self->save_action, enable);

enable = (item != NULL
&& ((load_state == PHOTOS_LOAD_STATE_FINISHED && mode == PHOTOS_WINDOW_MODE_PREVIEW) || selection_mode)
&& photos_share_point_manager_can_share (PHOTOS_SHARE_POINT_MANAGER (self->shr_pnt_mngr), item));
g_simple_action_set_enabled (self->share_action, enable);

can_open = FALSE;
can_trash = selection != NULL;
for (l = selection; l != NULL; l = l->next)
{
PhotosBaseItem *selected_item;
const gchar *urn = (gchar *) l->data;

/* When PhotosItemManager::items-changed is emitted, a selected
* item can potentially be removed from the item manager.
*/
selected_item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->state->item_mngr, urn));
if (selected_item == NULL)
continue;

can_trash = can_trash && photos_base_item_can_trash (selected_item);

if (photos_base_item_get_default_app_name (selected_item) != NULL)
can_open = TRUE;
}

enable = ((load_state == PHOTOS_LOAD_STATE_FINISHED
&& mode == PHOTOS_WINDOW_MODE_PREVIEW
&& photos_base_item_can_trash (item))
|| (selection_mode && can_trash));
g_simple_action_set_enabled (self->delete_action, enable);

enable = ((load_state == PHOTOS_LOAD_STATE_FINISHED && mode == PHOTOS_WINDOW_MODE_PREVIEW)
|| (selection_mode && can_open));
g_simple_action_set_enabled (self->open_action, enable);

enable = (load_state == PHOTOS_LOAD_STATE_FINISHED
&& mode == PHOTOS_WINDOW_MODE_PREVIEW
&& photos_base_item_can_edit (item));
g_simple_action_set_enabled (self->edit_action, enable);
}


There. WHEW
All one function function.
FUCK your meme language.

gitlab.gnome.org/GNOME/gnome-photos/blob/master/src/photos-application.c

C applications fucking suck. Most just poorly re-implement C++'s OOP features with base-structs in macros and pointer casting and all that bullshit.

It's like seeing someone insisting on using a rock to drive nails instead of a hammer and insisting this is somehow "more efficient", even when you show them what code gets created and how a C++ compiler does better due to abstraction, where the compiler actually understands what you're trying to do.

This. People are just afraid old dogs like Linus, Stallman, and their thousands of bitch suck-ups will bully them if they use non-meme languages.

C is good if you want your project to take 1000x as long to complete (probably not even exaggerating), have bugs and security issues unique to the language (stack overflows, buffers overflows, memory leaks) and want to end up with an unreadable mess that follows no coding standards and patterns whatsoever, so that nobody else has any chance to ever understand what your code does - especially if you go crazy with macros, which is what C developers LOVE to do, in order to poorly re-invent features other languages already have.

You think that is complicated? Try the eval loop for CPython (1500 line switch statement):
github.com/python/cpython/blob/master/Python/ceval.c#L1115

Oh god. Well I guess that's just computer generated or something. But somebody actually sat down and wrote the 9000 line function I pasted.

Not really their fault, GTK's API is complete and utter garbage.

Where is the problem with that? Seems fine to me if it works.

GNU code is autism. Have you seen the comparison images between GNU source and OpenBSD?

>REEEEEEE THE C CODE IS BUGGY WHEN I WRITE IT
>REEEEEEE I CANT UNDERSTAND C
>REEEEEEEEE C IS SLOW TO RUN AND EVEN SLOWER TO WRITE WHEN I WRITE IT

Ever heard the term projecting?

Attached: b2c[1].png (1000x861, 259K)

No, that is not computer generated.

ever wondered why people dislike GLib and GTK? ever wondered why Gnome is such trash?

this. Gtk sux

>Have you seen the comparison images between GNU source and OpenBSD?
No, post it.

Yes and I'm not projecting. That is a horrible 9000 line program. There is no reason at all for 9000 line programs to exist.

Not him but just open up BSD and GNU side by side and compare common apps like ls, cat, time, etc

I don't see what the issue here is, have you ever developed a stateful GUI application before?

Do you think porting it to C++, Rust, Javascript, Go, or whatever meme language you like would make the logic any less complicated?

Do you think splitting the function across 12 files would make it any easier to read or change?

Would you prefer they did stuff like "#define g_simple_action_set_enabled E" at the top of the function so it technically becomes shorter?

The issue is the logic gets wasted in the convoluted C syntax.

The funny thing is that Linux itself does use many object oriented techniques, see lwn.net/Articles/444910/
Also, the kernel got much better, code quality-wise, after Linus started simply limiting himself to approve/reject commits. Not to mention that most of the criticisms by these "old dogs" refers to C++ before the C++11 standard, which massively improved the language.

>object oriented techniques
>C
I don't wanna hear about it

Did you even read the article he linked? OOP is used in C way more often than most people care to admit.

To be quite frank, I'm too lazy at the current moment.

i'd rather define the UI in markup and glue it together with something high level, it's pointless doing it imperatively in C

>Do you think splitting the function across 12 files would make it any easier to read or change?
yes and yes

>a bunch of boolean expressions
>convoluted syntax
???

Way to out yourself as a clueless webshit

Then go do that, submit it as a patch and see what they say

> be you
> a lamer
> can't code
> doesn't understand C
you'll fit right in here on Jow Forums

>Then go do that, submit it as a patch and see what they say
they would thank me for organizing their pajeet tier code

gtk sucks, big news

>Then go do that, submit it as a patch and see what they say
im sure the conversation would go like this:
> NICE WORK, FAGGOT.
> submissions: laughed at and deleted

>t. writes code not even he himself can understand
Retards

C++ syntax is fucking disgusting unless you use Qt though

> be you
> retarded
> so illiterate that reading is impossible
that code is so simple to understand. you haven't seen much C code before have you, faggot? or had to deal with gtk? this is nothing. you fucking morons think anything greater than microsoft BASIC or python is TOO COMPLEX TO UNDERSTAND. my fucking sides.

It's not complex, it's trash. 90% of C code ever is just syntax and single-character variable names. Good riddance.

you think we think this is complex but we fucking don't you absolute faggot
the code is just garbage

>t. pajeet webdev

Attached: Untitled.png (736x283, 30K)

>gtk
We already know it's absolute shit.

>pajeet webdev
since when does a pajeet web dev care about minimizing lines of code? get your memes right sœybœy

>thinks it's too hard to write good C
>can't understand C
>wants to use more pajeet tier languages
>not a pajeet webdev

Just getting into PIC controllers. Any /PIC/ bois got any cool projects or tips to share?

>>thinks it's too hard to write good C
>>can't understand C
holy fuck you're insecure af

make a PIC based arduino, promptly shove it into your ass

Why does C make kiddos so mad?

I have a question. I'm looking through this code and can't really think of a good way of decomposing it other than *maybe* splitting things up into general categories, and going from there.

How would you guys have designed it? Because I do agree, this looks like a pain in the butt to debug.

>>>thinks it's too hard to write good C
>>can't understand C

>C is good if you want your project to take 1000x as long to complete (probably not even exaggerating), have bugs and security issues unique to the language (stack overflows, buffers overflows, memory leaks) and want to end up with an unreadable mess that follows no coding standards and patterns whatsoever, so that nobody else has any chance to ever understand what your code does - especially if you go crazy with macros, which is what C developers LOVE to do, in order to poorly re-invent features other languages already have.
>The issue is the logic gets wasted in the convoluted C syntax.

>stack overflows
>buffers overflows
>memory leaks
>bugs and security issues unique to the language
whoever wrote that your mom's a hoe

>The issue is the logic gets wasted in the convoluted C syntax.
>GTK's shit API is the same as C's syntax

Attached: 1520001783272.jpg (800x450, 45K)

sometimes you just need a big switch or if/else ladder, its just how logic works specially in low level code

This

Attached: d8783177-07c7-4b00-84dd-70884653ded4..png (512x494, 130K)

looks good to me.

breaking news gtk devs are shit
nothing new under the sun, delete your thread
read x264 source code if you want to see good C.
If you still find it shit, you're not qualified to have an opinion on the matter.

Even fucking Racket can do something WAY more elegant than this. This is just diarrhea.

STMicroelectronics cuck here
tfw running on battery but only 16 MHz

The rust language itself offers nothing new and is poorly implemented. So what's left besides marketing wank and the community full of shills who harass everyone.

yeah, lets just ignore the fact that higher-level languages like Haskell and Python compile to/are interpreted in C.

>how a C++ compiler does better due to abstraction
C intentionally keeps abstraction to minimum because it's supposed to be "close to the metal" in terms of how the machine code it compiles into actually runs.

Developers who implement the abstractions that languages like C++ provide are using the language wrong. If you do want to write programs with decent levels of abstraction, which is perfectly reasonable, then you shouldn't be writing in C.

PS, OOP = BS